简体   繁体   English

使用 Python3 创建 virtualenv 时出错

[英]Error creating virtualenv with Python3

I'm working on Linux Mint 17 and I'm trying to create a new virtualenv with Python3 like this:我正在 Linux Mint 17 上工作,我正在尝试使用 Python3 创建一个新的 virtualenv,如下所示:

python3.6 -m venv env

And this is the error that I get:这是我得到的错误:

Error: Command '['/home/ric/myprojs/django-example-channels/env/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

I've googled this error message but haven't managed to find anything too informative.我在谷歌上搜索了这条错误消息,但没有找到任何信息量太大的信息。

This is my pip version, in case it make any difference:这是我的 pip 版本,以防万一:

pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

I've been using Python2 for some time, but I'm new to Python3.我已经使用 Python2 有一段时间了,但我是 Python3 的新手。 I don't know what I may be missing.我不知道我可能会错过什么。

UPDATE 1:更新1:

Answering @cezar's question, when I type which python3 this is what I get:回答@cezar 的问题,当我输入which python3这是我得到的:

$ which python3
/usr/bin/python3

UPDATE 2:更新 2:

Answering @Chłop Z Lasu:回答@Chłop Z Lasu:

$ virtualenv -p python3.6 env
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/ric/myprojs/django-example-channels/example_channels/env/bin/python3.6
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2328, in <module>
    main()
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 925, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1231, in install_python
    shutil.copyfile(executable, py_executable)
  File "/usr/lib/python3.6/shutil.py", line 104, in copyfile
    raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

The error indicates that virtualenv is trying to make an environment in your python path.该错误表明 virtualenv 正在尝试在您的 python 路径中创建一个环境。 therefore, you have to specify your virtualenv destination因此,您必须指定您的 virtualenv 目标

virtualenv -p python3.6 /path/to/yourenv

For venv and python3.6 installing venv one can use below to fix the issue对于 venv 和 python3.6 安装 venv 可以使用下面的来解决问题

sudo apt install python3.6-venv须藤 apt 安装 python3.6-venv

您必须通过以下代码安装 venv:

sudo apt install python3.6-venv

Expanding on the Answer Above:扩展上面的答案:

The error indicates that virtualenv is trying to make an environment in your python path.该错误表明 virtualenv 正在尝试在您的 python 路径中创建一个环境。 therefore, you have to specify your virtualenv destination因此,您必须指定您的 virtualenv 目标

Since -p is a flag equivalent to --python, you can also use.由于 -p 是等效于 --python 的标志,因此您也可以使用。

$ virtualenv --python=python3.6 /path/to/yourenv

Or或者

$ virtualenv -p python3.6 /path/to/yourenv 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM