在`virtualenv .`

时间:2018-02-11 19:36:36

标签: python python-3.x virtualenv

我正在尝试设置普通的python3虚拟环境。

我创建了我的虚拟环境并将其激活

virtualenv . && source bin/activate

但是当我python3 --versionpip3 freeze时,我看到的不仅仅是默认的python3库。

以下是python3 --version输出

(socketdirectory) lawn-143-215-57-83:socketdirectory jaeminbaek$ python3 --version
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)

这是pip3 freeze结果输出

zewn-143-215-57-83:socketdirectory mycomputer$ source bin/activate pip3 freeze
backports.weakref==1.0rc1
bleach==1.5.0
certifi==2017.7.27.1
chardet==3.0.4
configparser==3.5.0
defusedxml==0.5.0
Django==1.11.4
django-allauth==0.32.0
django-crispy-forms==1.6.1
django-filter==1.0.4
django-widget-tweaks==1.4.1
djangorestframework==3.6.3
enum34==1.1.6
flake8==3.4.1
flake8-docstrings==1.1.0
flake8-polyfill==1.0.1
html5lib==0.9999999
idna==2.5
Keras==2.0.6
Markdown==2.6.8
mccabe==0.6.1
numpy==1.13.1
oauthlib==2.0.2
olefile==0.44
Pillow==4.2.1
protobuf==3.3.0
pycodestyle==2.3.1
pydocstyle==2.0.0
pyflakes==1.5.0
python3-openid==3.1.0
pytz==2017.2
PyYAML==3.12
requests==2.18.3
requests-oauthlib==0.8.0
scipy==0.19.1
six==1.10.0
snowballstemmer==1.2.1
tensorflow==1.2.1
Theano==0.9.0
urllib3==1.22
Werkzeug==0.12.2

为什么要导入这么多的库?

更新我在使用virtualenv -p python3 venv

时收到此错误
lawn-143-215-57-83:socketdirectory jaeminbaek$ virtualenv -p python3 venv 
Running virtualenv with interpreter /Users/jaeminbaek/anaconda/bin/python3
Using base prefix '/Users/jaeminbaek/anaconda'
New python executable in /Users/jaeminbaek/Desktop/cs3251/socketdirectory/venv/bin/python3
Not overwriting existing python script /Users/jaeminbaek/Desktop/cs3251/socketdirectory/venv/bin/python (you must use /Users/jaeminba
dyld: Library not loaded: @rpath/libpython3.6m.dylib
  Referenced from: /Users/jaeminbaek/Desktop/cs3251/socketdirectory/venv/bin/python3
  Reason: image not found
ERROR: The executable /Users/jaeminbaek/Desktop/cs3251/socketdirectory/venv/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/Users/jaeminbaek/Desktop/cs3251/socketdirectory' (should be '/Users/jaeminbaek/Desktop/cs3251/socket
ERROR: virtualenv is not compatible with this system or executable
lawn-143-215-57-83:socketdirectory jaeminbaek$ 

1 个答案:

答案 0 :(得分:3)

您正在使用python 2.7

创建虚拟环境
pip freeze

当您触发哪个pip3时它不会显示新虚拟环境下的pip,它将显示包含许多库的全局pip3。

要执行pip3,您应该通过显式提供python3标志来创建虚拟环境

virtualenv -p python3 . && source bin/activate
pip3 freeze
pip freeze

这将为您提供正确的结果。交叉检查总是激活命令

which pip
which pip3

上面的命令将显示您正在使用的是哪个点。在您的情况下,使用了usr / bin / pip3