在Ubuntu 16.04中使用virtualenv包时遇到语法错误。

huangapple go评论60阅读模式
英文:

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 &quot;/home/sbedanabett/.local/bin/virtualenv&quot;, line 7, in &lt;module&gt;
    from virtualenv.__main__ import run_with_catch
  File &quot;/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/__init__.py&quot;, line 1, in &lt;module&gt;
    from .run import cli_run, session_via_cli
  File &quot;/home/sbedanabett/.local/lib/python3.5/site-packages/virtualenv/run/__init__.py&quot;, line 70
    raise RuntimeError(f&quot;failed to find interpreter for {discover}&quot;)
                                                                  ^
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

huangapple
  • 本文由 发表于 2023年4月4日 13:44:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定