gpt4 book ai didi

python - 当同时安装了 python 2.7 和 3.6 时,对 python 3 模块使用 python 3.6 venv

转载 作者:太空宇宙 更新时间:2023-11-04 04:27:46 29 4
gpt4 key购买 nike

我想我没有在 Python 3 中获得 venv 模块。我有一个 AWS EC2 实例,其中有 yum安装了(对于 python)我在下面列出的内容……因此默认为 pythonpip适用于 2.7 而 python3命令是 3.6.5。挂牌pip freeze 2.7 默认安装了一堆东西,但运行 python3 -m pip freeze显示 3.6.5 似乎没有安装任何东西。我认为我可以通过为我使用 python 3 脚本的工作设置一个 venv 来更安全地安装一些模块。

使用 python3 -m venv ~/venv/aws然后我能够. venv/aws/bin/activate没问题。现在python --version仍然是 2.7.14,但我认为为 python3 安装一些东西是一个很好的测试在激活的 venv 中将是 python3 -m pip install --upgrade pip .这是行不通的,因为首先它说它正在卸载 pip 9.0.3,然后它继续进行并出现链接错误:

Collecting pip
Using cached https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Exception:
Traceback (most recent call last):
File "/usr/lib64/python3.6/shutil.py", line 544, in move
os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/usr/bin/pip' -> '/tmp/pip-183iq_uq-uninstall/usr/bin/pip'

我认为问题是在激活 venv 时我没有得到 venv/aws/bin用于pip pip3 python也不python3所以……激活有什么问题,我应该以不同的方式创建它吗?

yum 软件包列表:

libxml2-python27.x86_64              2.9.1-6.3.52.amzn1            @amzn-updates
newt-python27.x86_64 0.52.11-3.11.amzn1 installed
python26.x86_64 2.6.9-2.89.amzn1 @amzn-main
python26-libs.x86_64 2.6.9-2.89.amzn1 @amzn-main
python27.x86_64 2.7.14-1.123.amzn1 @amzn-updates
python27-PyYAML.x86_64 3.10-3.10.amzn1 installed
python27-babel.noarch 0.9.4-5.1.8.amzn1 installed
python27-backports.x86_64 1.0-3.14.amzn1 installed
python27-backports-ssl_match_hostname.noarch
3.4.0.2-1.12.amzn1 installed
python27-beautifulsoup4.noarch 4.6.0-1 @emr-platform
python27-boto.noarch 2.48.0-1.2.amzn1 installed
python27-botocore.noarch 1.8.13-1.66.amzn1 @amzn-main
python27-chardet.noarch 2.0.1-7.7.amzn1 installed
python27-colorama.noarch 0.2.5-1.7.amzn1 installed
python27-configobj.noarch 4.7.2-7.15.amzn1 installed
python27-crypto.x86_64 2.6.1-1.15.amzn1 @amzn-main
python27-daemon.noarch 1.5.2-1.5.amzn1 installed
python27-dateutil.noarch 2.1-1.3.amzn1 installed
python27-devel.x86_64 2.7.14-1.123.amzn1 @amzn-updates
python27-docs.noarch 2.7.10-1.21.amzn1 @amzn-main
python27-docutils.noarch 0.11-1.15.amzn1 installed
python27-ecdsa.noarch 0.11-3.3.amzn1 installed
python27-futures.noarch 3.0.3-1.3.amzn1 installed
python27-imaging.x86_64 1.1.6-19.9.amzn1 installed
python27-iniparse.noarch 0.3.1-2.1.9.amzn1 installed
python27-jinja2.noarch 2.7.2-2.15.amzn1 installed
python27-jmespath.noarch 0.9.2-1.12.amzn1 installed
python27-jsonpatch.noarch 1.2-2.5.amzn1 installed
python27-jsonpointer.noarch 1.0-3.4.amzn1 installed
python27-kitchen.noarch 1.1.1-5.6.amzn1 installed
python27-libs.x86_64 2.7.14-1.123.amzn1 @amzn-updates
python27-lockfile.noarch 0.8-3.5.amzn1 installed
python27-markupsafe.x86_64 0.11-4.6.amzn1 installed
python27-nltk.noarch 3.3-1 @emr-platform
python27-nose.noarch 1.3.0-1.11.amzn1 @amzn-main
python27-numpy.x86_64 1.14.5-1 @emr-bigtop
python27-paramiko.noarch 1.15.1-2.6.amzn1 @amzn-main
python27-pip.noarch 9.0.3-1.26.amzn1 @amzn-updates
python27-ply.noarch 3.4-3.12.amzn1 installed
python27-pyasn1.noarch 0.1.7-2.9.amzn1 installed
python27-pycurl.x86_64 7.19.0-17.12.amzn1 installed
python27-pygpgme.x86_64 0.3-9.12.amzn1 installed
python27-pyliblzma.x86_64 0.5.3-11.6.amzn1 installed
python27-pystache.noarch 0.5.3-2.8.amzn1 installed
python27-pyxattr.x86_64 0.5.0-1.6.amzn1 installed
python27-requests.noarch 1.2.3-5.10.amzn1 installed
python27-rsa.noarch 3.4.1-1.8.amzn1 installed
python27-sagemaker_pyspark.noarch 1.1.0-1 @emr-bigtop
python27-setuptools.noarch 36.2.7-1.33.amzn1 installed
python27-simplejson.x86_64 3.6.5-1.12.amzn1 installed
python27-six.noarch 1.8.0-1.23.amzn1 installed
python27-test.x86_64 2.7.14-1.123.amzn1 @amzn-updates
python27-tools.x86_64 2.7.14-1.123.amzn1 @amzn-updates
python27-urlgrabber.noarch 3.10-8.16.amzn1 installed
python27-urllib3.noarch 1.8.2-1.5.amzn1 installed
python27-virtualenv.noarch 15.1.0-1.14.amzn1 installed
python27-windmill.noarch 1.6-1 @emr-platform
python34.x86_64 3.4.8-1.39.amzn1 @amzn-updates
python34-beautifulsoup4.noarch 4.6.0-1 @emr-platform
python34-boto.noarch 2.48.0-1 @emr-platform
python34-dateutil.noarch 2.2-1 @emr-platform
python34-jmespath.noarch 0.9.3-1 @emr-platform
python34-libs.x86_64 3.4.8-1.39.amzn1 @amzn-updates
python34-lxml.x86_64 4.2.1-1 @emr-platform
python34-mysqlclient.x86_64 1.3.12-1 @emr-platform
python34-nltk.noarch 3.3-1 @emr-platform
python34-nose.noarch 1.3.7-1 @emr-platform
python34-numpy.x86_64 1.14.5-1 @emr-bigtop
python34-pytz.noarch 2018.4-1 @emr-platform
python34-pyyaml.x86_64 3.12-1 @emr-platform
python34-sagemaker_pyspark.noarch 1.1.0-1 @emr-bigtop
python34-six.noarch 1.11.0-1 @emr-platform
python34-windmill.noarch 1.6-1 @emr-platform
python36.x86_64 3.6.5-1.9.amzn1 @amzn-updates
rpm-python26.x86_64 4.11.3-21.75.amzn1 amzn-main
rrdtool-python26.x86_64 1.4.8-3.18.amzn1 amzn-main
rrdtool-python27.x86_64 1.4.8-3.18.amzn1 amzn-main
samba-python.x86_64 4.6.2-12.37.amzn1 amzn-main
setools-libs-python.x86_64 3.3.7-34.23.amzn1 amzn-main
subversion-python26.x86_64 1.9.7-1.58.amzn1 amzn-main
subversion-python27.x86_64 1.9.7-1.58.amzn1 amzn-main
systemtap-runtime-python2.x86_64 3.2-2.35.amzn1 amzn-updates
unbound-python.x86_64 1.6.6-1.4.amzn1 amzn-updates
yum-metadata-parser-python26.x86_64 1.1.4-10.20.amzn1 amzn-main
yum-python26.noarch 3.4.3-150.70.amzn1 amzn-main

最佳答案

使用virtualenv创建环境

如果还没有安装

  • yum 安装 virtualenv

然后用 -p 设置你想使用的 python3 解释器的路径

  • virtualenv -p/path/to/python3/path/to/virtual/environment

关于python - 当同时安装了 python 2.7 和 3.6 时,对 python 3 模块使用 python 3.6 venv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204821/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com