英文:
Getting syntax error while using virtualenv package in Ubuntu 16.04
问题
我在 VMware 虚拟环境中运行 Ubuntu 16.04。当我尝试安装 virtualenv 时,遇到了问题。
我做了以下操作:
sudo apt install python3-pip
sudo pip3 install virtualenv
virtualenv --version
最后一个命令显示如下:
Traceback (most recent call last):
File "/home/sbedanabett/.local/bin/virtualenv", line 7, in <module>
from virtualenv.__main__ import run_with_catch
File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/__init__.py", line 1, in <module>
from .run import cli_run, session_via_cli
File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/run/__init__.py", line 70
raise RuntimeError(f"failed to find interpreter for {discover}")
^
SyntaxError: invalid syntax
这似乎是因为它正在使用 Python2 解释器。但我已将默认解释器更改为 Python3,遵循此问题。因此,我对这个错误感到困惑。
$ python --version
Python 3.5.2
$ python2 --version
Python 2.7.12
英文:
I am running Ubuntu 16.04 in VMware virtual environment. When I try to install virtualenv, I am facing issues.
What I did:
sudo apt install python3-pip
sudo pip3 install virtualenv
virtualenv --version
The last command is showing this:
Traceback (most recent call last):
File "/home/sbedanabett/.local/bin/virtualenv", line 7, in <module>
from virtualenv.__main__ import run_with_catch
File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/__init__.py", line 1, in <module>
from .run import cli_run, session_via_cli
File "/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/run/__init__.py", line 70
raise RuntimeError(f"failed to find interpreter for {discover}")
^
SyntaxError: invalid syntax
This seems because it is using Python2 interpreter. But I have changed my default interpreter to be Python3, following this question. So I am clueless why this error.
$ python --version
Python 3.5.2
$ python2 --version
Python 2.7.12
答案1
得分: 1
要安装旧版本的virtualenv,请尝试以下命令:
例如,要安装16.7.9版本:
pip install https://github.com/pypa/virtualenv/tarball/16.7.9
要在本地安装:
pip install --user https://github.com/pypa/virtualenv/tarball/16.7.9
在运行virtualenv
命令时,使用python -m
,例如:
python -m virtualenv --version
英文:
To install an older version of virtualenv you try this command
For example to install 16.7.9
pip install https://github.com/pypa/virtualenv/tarball/16.7.9
To install in local
pip install --user https://github.com/pypa/virtualenv/tarball/16.7.9
and while running the command line for virtualenv
use python -m
Example
python -m virtualenv --version
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论