无法使用Python 2.7创建虚拟环境。

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

Can't create virtual environment with python 2.7

问题

我尝试在CentOS服务器上使用自定义的Python 2.7.15创建虚拟环境,我按照这个网站的步骤进行操作(https://help.dreamhost.com/hc/en-us/articles/215489338-Installing-and-using-virtualenv-with-Python-2),但是当我使用virtualenv创建Python虚拟环境时出现了一些问题。以下是代码。

$ virtualenv -p /public/home/myname/opt/python-2.7.15/bin/python venv
RuntimeError: failed to query /public/home/myname/opt/python-2.7.15/bin/python with code 1 err: '  File "/public/home/myname/.local/lib/python3.8/site-packages/virtualenv/discovery/py_info.py", line 152\n    os.path.join(base_dir, exe) for exe in (f"python{major}", f"python{major}.{minor}")\n                                                           ^\nSyntaxError: invalid syntax\n'

我在网上搜索了答案,但未能找到解决方法,有人可以解释发生了什么吗?是Anaconda阻止我创建虚拟环境吗?

我搜索了这个错误,但似乎没有人遇到与我相同的错误。

英文:

I' trying to create a virtual environment with a custom python 2.7.15 on a centOS server,I followed the steps from this website (https://help.dreamhost.com/hc/en-us/articles/215489338-Installing-and-using-virtualenv-with-Python-2),but when I use virtualenv to create a python virtual environment something happens.Here is the code.

$ virtualenv -p /public/home/myname/opt/python-2.7.15/bin/python venv
RuntimeError: failed to query /public/home/myname/opt/python-2.7.15/bin/python with code 1 err: '  File "/public/home/myname/.local/lib/python3.8/site-packages/virtualenv/discovery/py_info.py", line 152\n    os.path.join(base_dir, exe) for exe in (f"python{major}", f"python{major}.{minor}")\n                                                           ^\nSyntaxError: invalid syntax\n'

I've searched the net for answer but I failed to reach one,can anyone explain what happened? Is the anaconda that prevents me from creating my virtual environment?

I searched the Error but it seems no one came across with the same error I met.

答案1

得分: 0

你必须使用已安装的 Python 2.7 版本的 virtualenv。安装/升级工具:

$ /public/home/myname/opt/python-2.7.15/bin/python -m pip install --upgrade "pip<21.0"
$ /public/home/myname/opt/python-2.7.15/bin/python -m pip install --upgrade virtualenv

现在创建虚拟环境:

$ /public/home/myname/opt/python-2.7.15/bin/python -m virtualenv venv
英文:

You must use virtualenv installed for Python 2.7. Install/upgrade tools:

$ /public/home/myname/opt/python-2.7.15/bin/python -m pip install --upgrade &quot;pip&lt;21.0&quot;
$ /public/home/myname/opt/python-2.7.15/bin/python -m pip install --upgrade virtualenv

Now create the venv:

$ /public/home/myname/opt/python-2.7.15/bin/python -m virtualenv venv

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

发表评论

匿名网友

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

确定