【发布时间】:2020-05-16 03:56:48
【问题描述】:
我正在做一个需要从 python2.7 移植到 python3.7 的大项目。 对于开发,我依赖于虚拟环境。
对于 2.7v,我使用的是使用 virtualenv 模块创建的虚拟环境,它是包 virtualenvwrapper 和 virtualenvwrapper-win。
对于 3.7v,我尝试使用相同的包创建一个 env,这次我将它们安装到 python3.7 目录。我设法用自己的环境变量设置了 python3.7,将其命名为python3.exe,这样我就可以选择在哪里安装额外的 python 包。
即
pip install virtualenv - 在python2.7目录下安装Virtualenv,但是
python3 -m pip install virtualenv - 安装到python3.7目录
C:\Users\user1>pip freeze
...
stevedore==1.30.1
virtualenv==16.4.3
virtualenv-clone==0.5.1
virtualenvwrapper==4.8.4
virtualenvwrapper-win==1.2.5
对比
C:\Users\user1>python3 -m pip freeze
...
stevedore==1.31.0
virtualenv==16.7.5
virtualenv-clone==0.5.3
virtualenvwrapper==4.8.4
virtualenvwrapper-win==1.2.5
到目前为止一切顺利。
当我想用 python3.7 创建一个名为envTest 的虚拟环境时,这是我使用的命令:
mkvirtualenv python3 envTest
为了避免进一步的错误识别,我将本地环境文件夹中的新 python 可执行文件重命名为python0.exe。
现在,我可以检查所有三个可用 python 源(python.exe=python2.7、python3.exe=python3.7 和 python0.exe= 虚拟环境中的 python 可执行文件)的路径和版本。
但是,这是我得到的:
(envTest) C:\Users\user1\projects\env_testing>whereis python
C:\Python27\python.exe
(envTest) C:\Users\user1\projects\env_testing>whereis python3
C:\Users\user1\AppData\Local\Programs\Python\Python37\python3.exe
(envTest) C:\Users\user1\projects\env_testing>whereis python0
C:\Users\user1\Envs\envTest\Scripts\python0.exe
(envTest) C:\Users\user1\projects\env_testing>python --version
Python 2.7.16
(envTest) C:\Users\user1\projects\env_testing>python3 --version
Python 3.7.4
(envTest) C:\Users\user1\projects\env_testing>python0 --version
Python 2.7.16
(envTest) C:\Users\user1\projects\env_testing>
在我看来,就像我在创建 envTest 环境时没有得到正确的 virtualenvwrapper,从而间接调用了错误的 python 版本。
我该如何解决这个问题?
我也尝试简单地尝试 python3.x 内置 venv,但使用它时,我收到一条错误消息:
C:\Users\user1\projects>python3 -m venv ./venv_Test venvEnv
Error: [WinError 2] The system cannot find the file specified
即使它创建了以下目录,尽管没有 python 可执行文件
C:\Users\user1\projects\venv_Test>dir
...
30.01.2020 14:41 <DIR> .
30.01.2020 14:41 <DIR> ..
30.01.2020 14:41 <DIR> Include
30.01.2020 14:41 <DIR> Lib
30.01.2020 14:41 117 pyvenv.cfg
30.01.2020 14:41 <DIR> Scripts
...
【问题讨论】:
标签: python-3.x windows-10 virtualenv virtualenvwrapper python-venv