【发布时间】:2022-11-03 21:13:20
【问题描述】:
我尝试在服务器上使用pipenv
task :migrate do on roles(:app) do
execute "cd #{release_path} && /home/ubuntu/.pyenv/shims/pipenv install"
execute "cd #{release_path} && /home/ubuntu/.pyenv/shims/pipenv run python #{release_path}/manage.py makemigrations"
execute "cd #{release_path} && /home/ubuntu/.pyenv/shims/pipenv run python #{release_path}/manage.py migrate"
end
我的Pipfile 在这里
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
django = "*"
pandas = "*"
djangorestframework = "*"
markdown = "*"
django-filter = "*"
django-webpack-loader = "*"
django-crispy-forms = "*"
pymysql = "*"
beautifulsoup4 = "*"
[dev-packages]
[requires]
python_version = "3.9"
然后错误信息在这里,
看起来 pipenv install 成功但 Django 未正确安装。
怎么了?
DEBUG [42151ee5] Installing dependencies from Pipfile.lock (4abb36)...
DEBUG [42151ee5] To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
INFO [42151ee5] Finished in 19.917 seconds with exit status 0 (successful).
INFO [35fb8a90] Running cd /var/www/html/myappp/releases/20220923122448 && /home/ubuntu/.pyenv/shims/pipenv run python /var/www/html/myapp/releases/20220923122448/manage.py makemigrations as ubuntu@panda.example.jp
DEBUG [35fb8a90] Command: cd /var/www/html/muapp/releases/20220923122448 && /home/ubuntu/.pyenv/shims/pipenv run python /var/www/html/myapp/releases/20220923122448/manage.py makemigrations
DEBUG [35fb8a90] Traceback (most recent call last):
File "/home/ubuntu/.local/share/virtualenvs/20220923122448-VTt_Iizv/lib/python3.8/site-packages/django/utils/timezone.py", line 10, in <module>
import zoneinfo
ModuleNotFoundError: No module named 'zoneinfo'
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
【问题讨论】:
-
它正在寻找 Python 3.9 中引入的
zoneinfo模块。您运行的 Python 版本似乎比您安装的软件包所需的版本旧。 -
你是对的,我更新了python版本,它解决了,你救了我。