简体   繁体   English

Python 3 virtualenv 为什么找不到一些已安装的包?

[英]Why can't Python 3 virtualenv find some installed packages?

I am working with a Python virtualenv named env to execute Odoo.我正在使用名为env的 Python virtualenv 来执行 Odoo。 In the virtualenv bin directory, I got this:在 virtualenv bin目录中,我得到了这个:

pip
pip3
pip3.8

python -> /usr/bin/python3
python3 -> python
python3.8 -> python

And the Odoo service is running this command to execute Odoo (as you can see, using the python3.8 of the virtualenv): Odoo 服务正在运行这个命令来执行 Odoo(如您所见,使用 virtualenv 的python3.8 ):

ExecStart=/opt/odoo/env/bin/python3.8 /opt/odoo/odoo_13/src/oca/OCB/odoo-bin -c /opt/odoo/odoo_13/config/.odoo.conf

The problem is that every now and again, Odoo gives the following critical error and the instance stops working:问题是,Odoo 时不时地给出以下严重错误并且实例停止工作:

ModuleNotFoundError: No module named 'werkzeug' ModuleNotFoundError:没有名为“werkzeug”的模块

It seems that the werkzeug package is not installed, but, if I do the following:似乎未安装werkzeug package,但是,如果我执行以下操作:

anubia@my-server:/opt/odoo$ . env/bin/activate

(env) anubia@my-server:/opt/odoo$ which pip
/opt/odoo/env/bin/pip

(env) anubia@my-server:/opt/odoo$ which pip3
/opt/odoo/env/bin/pip3

(env) anubia@my-server:/opt/odoo$ which pip3.8
/opt/odoo/env/bin/pip3.8

(env) anubia@my-server:/opt/odoo$ pip3.8 install werkzeug
Requirement already satisfied: werkzeug in ./env/lib/python3.8/site-packages (0.11.15)

(env) anubia@my-server:/opt/odoo$ cd env/lib/python3.8/site-packages/
Display all 125 possibilities? (y or n)
Babel-2.9.1.dist-info/             attrs-21.2.0.dist-info/            docutils/                          numpy-1.21.0.dist-info/            python_stdnum-1.16.dist-info/      urllib3-1.26.6.dist-info/
Crypto/                            babel/                             docutils-0.17.1.dist-info/         numpy.libs/                        pytz/                              validate_email-1.3.dist-info/
Jinja2-3.0.1.dist-info/            bcrypt/                            gevent/                            paramiko/                          pytz-2021.1.dist-info/             vatnumber/
MarkupSafe-2.0.1.dist-info/        bcrypt-3.2.0.dist-info/            gevent-21.1.2.dist-info/           paramiko-2.7.2.dist-info/          reportlab/                         vatnumber-1.2.dist-info/
OpenSSL/                           cached_property-1.5.2.dist-info/   greenlet/                          passlib/                           reportlab-3.5.68.dist-info/        werkzeug/
PIL/                               cachetools/                        greenlet-1.1.0.dist-info/          passlib-1.7.4.dist-info/           reportlab.libs/                    wheel/
Pillow-8.3.1.dist-info/            cachetools-4.2.2.dist-info/        html2text/                         phonenumbers/                      requests/                          wheel-0.36.2.dist-info/
Pillow.libs/                       certifi/                           html2text-2020.1.16.dist-info/     phonenumbers-8.12.27.dist-info/    requests-2.25.1.dist-info/         xlrd/
PyNaCl-1.4.0.dist-info/            certifi-2021.5.30.dist-info/       idna/                              pip/                               requests_file-1.5.1.dist-info/     xlrd-2.0.1.dist-info/
PyPDF2/                            cffi/                              idna-2.10.dist-info/               pip-21.3.1.dist-info/              requests_toolbelt/                 xlsxwriter/
PyPDF2-1.26.0.dist-info/           cffi-1.14.5.dist-info/             isodate/                           pkg_resources/                     requests_toolbelt-0.9.1.dist-info/ xlwt/
PyYAML-3.12.dist-info/             cffi.libs/                         isodate-0.6.0.dist-info/           polib-1.1.1.dist-info/             sassutils/                         xlwt-1.3.0.dist-info/
Unidecode-1.2.0.dist-info/         chardet/                           jinja2/                            psutil/                            setuptools/                        xmlsig/
Werkzeug-0.11.15.dist-info/        chardet-4.0.0.dist-info/           libsass-0.21.0.dist-info/          psutil-5.8.0.dist-info/            setuptools-57.1.0.dist-info/       xmlsig-0.1.5.dist-info/
XlsxWriter-1.4.4.dist-info/        cryptography/                      lxml/                              psycopg2/                          six-1.16.0.dist-info/              yaml/
__pycache__/                       cryptography-3.4.7.dist-info/      lxml-4.6.3.dist-info/              psycopg2-2.9.1.dist-info/          stdnum/                            zeep/
_distutils_hack/                   dateutil/                          markupsafe/                        pyOpenSSL-20.0.1.dist-info/        suds/                              zeep-4.0.0.dist-info/
appdirs-1.4.4.dist-info/           decorator-5.0.9.dist-info/         nacl/                              pycparser/                         suds_jurko-0.6.dist-info/          zope/
asn1crypto/                        defusedxml/                        num2words/                         pycparser-2.20.dist-info/          tests/                             zope.event-4.5.0.dist-info/
asn1crypto-1.4.0.dist-info/        defusedxml-0.7.1.dist-info/        num2words-0.5.10.dist-info/        pycryptodome-3.10.1.dist-info/     unidecode/                         zope.interface-5.4.0.dist-info/
attr/                              docopt-0.6.2.dist-info/            numpy/                             python_dateutil-2.8.1.dist-info/   urllib3/

So werkzeug seems to be installed.所以似乎安装了werkzeug What is the problem?问题是什么?

EDIT编辑

After trying with @ChesuCR answer two weeks, the Odoo server stopped working again.在尝试使用@ChesuCR 回答两周后,Odoo 服务器再次停止工作。 This time the error is:这次的错误是:

ModuleNotFoundError: No module named 'PyPDF2'

However, if I check the virtualenv :但是,如果我检查virtualenv

myuser@myserver:/opt/odoo$ . venv3.7/bin/activate
(venv3.7) myuser@myserver:/opt/odoo$ which python3.7
/opt/odoo/venv3.7/bin/python3.7
(venv3.7) myuser@myserver:/opt/odoo$ python3.7 -m pip install PyPDF2
Requirement already satisfied: PyPDF2 in ./venv3.7/lib/python3.7/site-packages (1.26.0)
(venv3.7) myuser@myserver:/opt/odoo$ python3.7 -m pip list
Package           Version
----------------- ---------
appdirs           1.4.4
attrs             21.2.0
Babel             2.6.0
beautifulsoup4    4.10.0
cached-property   1.5.2
certifi           2021.10.8
cffi              1.15.0
chardet           3.0.4
cryptography      36.0.0
decorator         4.3.0
defusedxml        0.7.1
docutils          0.14
ebaysdk           2.1.5
gevent            1.5.0
greenlet          0.4.15
html2text         2018.1.9
idna              2.8
isodate           0.6.0
Jinja2            2.10.1
libsass           0.17.0
lxml              4.3.2
Mako              1.0.7
MarkupSafe        1.1.0
mock              2.0.0
num2words         0.5.6
ofxparse          0.19
passlib           1.7.1
pbr               5.8.0
Pillow            6.1.0
pip               21.3.1
polib             1.1.0
psutil            5.6.6
psycopg2          2.7.7
pyasn1            0.4.8
pyasn1-modules    0.2.8
pycparser         2.21
pydot             1.4.1
pyOpenSSL         21.0.0
pyparsing         2.2.0
PyPDF2            1.26.0
pyserial          3.4
python-dateutil   2.7.3
python-stdnum     1.17
pytz              2019.1
pyusb             1.0.2
qrcode            6.1
reportlab         3.5.13
requests          2.21.0
requests-toolbelt 0.9.1
setuptools        57.5.0
six               1.16.0
soupsieve         2.3.1
urllib3           1.24.3
vatnumber         1.2
vobject           0.9.6.1
Werkzeug          0.14.1
wheel             0.37.0
xlrd              1.1.0
XlsxWriter        1.1.2
xlwt              1.3.0
zeep              3.2.0

And of course Odoo is running with the Python interpreter of the virtualenv :当然,Odoo 正在使用virtualenv的 Python 解释器运行:

ExecStart=/opt/odoo/venv3.7/bin/python3.7 /opt/odoo/odoo_13/src/oca/OCB/odoo-bin -c /opt/odoo/odoo_13/config/.odoo.conf

Odoo 13 is not compatible with the Python 3.8 version . Odoo 13与 Python 3.8 版本不兼容 You can try with Python 3.7 or 3.6 versions.您可以尝试使用 Python 3.7 或 3.6 版本。

Anyway, many issues have been fixed, so I am not sure about the Python 3.8 incompatibility无论如何,很多问题都已经修复了,所以我不确定 Python 3.8 不兼容

If the problem still bothers you, try to install the exact versions that Odoo developers posted in the requirements.txt file, where dependencies should have been tested.如果问题仍然困扰您,请尝试安装 Odoo 开发人员在requirements.txt文件中发布的确切版本,其中应该已经测试了依赖项。 So you can install the right Werzeug version:因此,您可以安装正确的 Werzeug 版本:

pip install Werkzeug==0.14.1

Ah, and if you want to show all the installed packages you can do:啊,如果你想显示所有已安装的包,你可以这样做:

pip list

I don't know what Odoo is, but in order to find the packages, you usually need to "activate" the virtualenv.我不知道 Odoo 是什么,但为了找到包,您通常需要“激活”virtualenv。 Just like you did manually, but you also need that when Odoo is running the program.就像您手动操作一样,但在 Odoo 运行程序时您也需要这样做。 It is not enough to just call the correct python binary.仅仅调用正确的 python 二进制文件是不够的。 So you can either try to have Odoo activate the venv before it starts the program, or if not possible, emulate doing that (it's probably mostly setting PATH and PYTHONPATH environment variables)因此,您可以尝试让 Odoo 在启动程序之前激活 venv,或者如果不可能,请模拟这样做(它可能主要是设置 PATH 和 PYTHONPATH 环境变量)

May be you should try this: How to Install Odoo 13 on Ubuntu 18.04也许你应该试试这个: 如何在 Ubuntu 18.04 上安装 Odoo 13

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 Anaconda 安装 Python 找不到一些包? - Why can't my Anaconda install of Python find some packages? Python动态导入在Virtualenv中找不到包 - Python Dynamic Import Can't Find Packages in Virtualenv 已安装的Python程序包导致VirtualEnv发生冲突,但找不到并删除它 - Installed Python package is causing conflict for VirtualEnv but can't find and remove it Celery Supervisor Virtualenv找不到通过github安装的pip软件包 - Celery Supervisor Virtualenv can't find pip packages installed via github 无法在 python virtualenv 中安装本地包 - can't install local packages in python virtualenv 为什么uwsgi找不到用--user安装的python包? - Why doesn't uwsgi find python packages installed with --user? 虚拟环境问题:无法在虚拟环境中导入已安装的包 - Problem with virtual env: can't import installed packages in the virtualenv Django在virtualenv中找不到包 - Django can't find can't find packages in virtualenv 为什么我不能在我的主Python安装文件夹中插入安装包? Virtualenv妨碍了? - Why can't I pip install packages in my main Python installation folder? Virtualenv getting in the way? Python找不到与Conda一起安装的软件包 - Python doesn't find packages that are installed with Conda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM