无法在AWS bitnami django lightsail示例上导入pip模块

sshcrbum  于 2023-06-25  发布在  Go
关注(0)|答案(3)|浏览(109)

我遵循了django lightsail示例的AWS教程:https://aws.amazon.com/es/getting-started/hands-on/deploy-python-application/
我试图部署我自己的代码,但Apache在管道安装的模块上给我错误。
似乎示例有不同的路径。有人在django lightsail示例上部署了自定义的django项目?

[Sun Aug 16 22:58:29.402644 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250] mod_wsgi (pid=4065): Exception occurred processing WSGI script '/opt/bitnami/apps/django/django_projects/orderbot/ordermenu/wsgi.py'.
[Sun Aug 16 22:58:29.403437 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250] Traceback (most recent call last):
[Sun Aug 16 22:58:29.403493 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/apps/django/django_projects/orderbot/ordermenu/wsgi.py", line 22, in <module>
[Sun Aug 16 22:58:29.403504 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     application = get_wsgi_application()
[Sun Aug 16 22:58:29.403515 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Sun Aug 16 22:58:29.403521 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     django.setup(set_prefix=False)
[Sun Aug 16 22:58:29.403530 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
[Sun Aug 16 22:58:29.403535 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     apps.populate(settings.INSTALLED_APPS)
[Sun Aug 16 22:58:29.403544 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
[Sun Aug 16 22:58:29.403549 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     app_config = AppConfig.create(entry)
[Sun Aug 16 22:58:29.403558 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
[Sun Aug 16 22:58:29.403563 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     module = import_module(entry)
[Sun Aug 16 22:58:29.403571 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "/opt/bitnami/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Sun Aug 16 22:58:29.403578 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]     return _bootstrap._gcd_import(name[level:], package, level)
[Sun Aug 16 22:58:29.403587 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Sun Aug 16 22:58:29.403596 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Sun Aug 16 22:58:29.403606 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250]   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[Sun Aug 16 22:58:29.403626 2020] [wsgi:error] [pid 4065] [client 177.240.102.67:65250] ModuleNotFoundError: No module named 'phonenumber_field'
monwx1rj

monwx1rj1#

问题是“python将包安装在apache看不到的目录中”。
所以:包安装在'/home/bitnami/.local/lib/python3.8/site-packages/'中,Apache在'/opt/bitnami/python/lib/python3.8/site-packages/'中查找。
我遵循的临时解决方案是使用以下命令将包复制到Apache eyes文件夹:'cp -r /home/bitnami/.local/lib/python3.8/site-packages/* /opt/bitnami/python/lib/python3.8/site-packages/'

7jmck4yq

7jmck4yq2#

我也有同样的问题,为了解决这个问题,我做了sudo pip3 install xxx,它的作品。
如果没有sudo,包将转到/home/bitnami/.local/lib/python3.8/site-packages/,并与它一起转到/opt/bitnami/python/lib/python3.8/site-packages/。此目录是Apache搜索的目录。

piv4azn7

piv4azn73#

只需要使用root用户与sudo su命令的pip安装包,现在是由apache找到。

相关问题