问题是:
我有一个requirements.txt文件,看起来像:
BeautifulSoup==3.2.0
Django==1.3
Fabric==1.2.0
Jinja2==2.5.5
PyYAML==3.09
Pygments==1.4
SQLAlchemy==0.7.1
South==0.7.3
amqplib==0.6.1
anyjson==0.3
...
我有一个本地归档目录,包含所有包和其他包。
我用
bin/virtualenv testing
激活后,我尝试根据本地存档目录中的requirements.txt安装软件包。
source bin/activate
pip install -r /path/to/requirements.txt -f file:///path/to/archive/
我得到的一些输出似乎表明安装正常:
Downloading/unpacking Fabric==1.2.0 (from -r ../testing/requirements.txt (line 3))
Running setup.py egg_info for package Fabric
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no files found matching 'fabfile.py'
Downloading/unpacking South==0.7.3 (from -r ../testing/requirements.txt (line 8))
Running setup.py egg_info for package South
....
但后来的检查显示,没有一个软件包安装正确。我无法导入包,并且在virtualenv的站点包目录中找不到包。那么到底出了什么问题?
使用Python 3在虚拟env中安装requirements.txt文件:
我也有同样的问题。我试图在虚拟环境中安装requirements.txt文件。我找到了解决方案。
最初,我是这样创建virtualenv的:
virtualenv -p python3 myenv
使用以下方法激活环境:
source myenv/bin/activate
现在,我使用以下命令安装了requirements.txt文件:
pip3 install -r requirements.txt
安装成功,我能够导入模块。
我使用的很多系统都被开发人员“按照他们在互联网上找到的方向”搞砸了。您的pip和python不查看相同的路径/站点包是非常常见的。因此,当我遇到奇怪的事情时,我会这样做:
$ python -c 'import sys; print(sys.path)'
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
这是一个快乐的系统。
下面是一个不愉快的系统。(或者至少这是一个幸福无知的系统,会导致他人不快乐。)
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
$ which pip pip2 pip3
/usr/local/bin/pip
/usr/local/bin/pip3
这是不愉快的,因为pip(python3.6和)使用/usr/local/lib/python3.6/site-packages,而python(python2.7和)使用的是/usr/local/lib-python2.7/site-papackages
当我想确保将需求安装到正确的python时,我会这样做:
$ which -a python python2 python3
/usr/local/bin/python
/usr/bin/python
/usr/local/bin/python2
/usr/local/bin/python3
$ /usr/bin/python -m pip install -r requirements.txt
你听过,“如果它没有坏,就不要尝试修复它。”DevOps版本就是,“如果你没有坏,你可以解决它,就不要试图修复它