Python(2.7)の学習を開始し、問題に直面しました。私はウィンドウ10を使用しています。TypeError:相対インポートでは、Pythonでpackage引数が必要です
私は仮想環境(c:\ virtualenvs \ testenv)を作成し、それを有効にしました。私のアプリのフォルダパスはc:\ pyprojects \ pytestです。このフォルダにはrequirements.txtがあり、すべてのパッケージがリストされています。それはtestenvの下で成功し、すべての必要なパッケージをインストールし
(testenv) c:\pyprojects\pytest\pip install -r requirements.txt
よう
プロンプトが見えます。それから私は、次のコマンドを
(testenv) c:\pyprojects\pytest\python manage.py runserver
を実行し、以下のerror--
Unhandled exception in thread started by <function wrapper at 0x03ABF8F0>
Traceback (most recent call last):
File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\virtualenvs\testenv\lib\site-packages\django\core\management\commands\runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "C:\virtualenvs\testenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\virtualenvs\testenv\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\virtualenvs\testenv\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\virtualenvs\testenv\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "c:\python27\Lib\importlib\__init__.py", line 30, in import_module
raise TypeError("relative imports require the 'package' argument")
TypeError: relative imports require the 'package' argument
を得た今、私は、ファイルにチェック - C:PY __ \ Python27 \ Libの\のimportlib__initをし、それが
言います。if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
__import__(name)
return sys.modules[name]
私のアプリのフォルダには、特にsettings.pyというドットで始まるファイルはありません。私のAPPフォルダがメインのpythonパスに含まれていないのですか?私は何かが欠けている。
ご協力いただきまして誠にありがとうございます。
あなたの 'INSTALLED_APPS'設定を表示してください。 – knbk