简体   繁体   English

如何在已经安装 python3.8 的 anaconda 下安装 python2.7 包?

[英]How do I install python2.7 packages under anaconda with python3.8 already in place?

So the default of anaconda is python 3.8, but you can invoke python2 by running python2 a_py_script.py .所以 anaconda 的默认值是 python 3.8,但是您可以通过运行python2 a_py_script.py来调用 python2。 The issue comes from the fact that you'll need to import things (say biopython), and you can't import them as any conda install -c conda-forge biopython or pip install biopython will be understood to automatically slot it into python3.8 packages exclusively.问题在于您需要导入东西(比如 biopython),并且您不能将它们导入为任何conda install -c conda-forge biopythonpip install biopython将被理解为自动将其插入 python3。 8包独家。 I ask this because I have some python2.7 scripts that demand packages outside the default install scope and ideally I'd like to do this without having to create a new python=2.7 env and track down everything I need.我问这个是因为我有一些 python2.7 脚本需要默认安装 scope 之外的软件包,理想情况下我想这样做而不必创建一个新的python=2.7环境并跟踪我需要的一切。

I've tried pip2.7 install biopython and python2.7 -m pip install biopython to no avail.我试过pip2.7 install biopythonpython2.7 -m pip install biopython无济于事。 Could it be that I technically don't have python 2.7 even though I'm able to invoke it from command line via python2 because python3 just naturally has some special limited backwards compatibility to run my python2 scripts?难道我在技术上没有 python 2.7,即使我能够通过python2从命令行调用它,因为 python3 自然地具有一些特殊的有限向后兼容性来运行我的 python2 脚本? (I did notice that conda list includes only 3.8 and no mention of 2.7) (我确实注意到conda list仅包括 3.8 并且没有提及 2.7)

I've tried cloning my env but I don't know how to do it in such a way that swapts just the version of python.我已经尝试克隆我的环境,但我不知道如何以仅交换 python 版本的方式进行操作。 conda create --name py27test --clone base python=2.7 says too many arguments. conda create --name py27test --clone base python=2.7说 arguments 太多。 I'd like to know if this is even advisible as my base environment I would presume is entirely built off of v3.8 so swapping out the python versions will just be bad time hence why this seems impossible?我想知道这是否甚至是可取的,因为我认为我的基本环境完全是基于 v3.8 构建的,所以更换 python 版本将是一个糟糕的时间,因此为什么这似乎是不可能的?

You can't mix Python versions in a conda environment.您不能在 conda 环境中混合 Python 版本。 You can call Python executables from outside your environment, but that's unadvisable for anything requiring dependencies.您可以从您的环境外部调用 Python 可执行文件,但这对于任何需要依赖项的东西都是不可取的。 If you must use Python 2.7 and need dependencies installed, that needs to be done in a contained environment, one that does not mix Python 3 packages into it.如果您必须使用 Python 2.7 并且需要安装依赖项,则需要在包含的环境中完成,该环境不会将 Python 3 个包混合到其中。

If you care about using your Python 2.7 scripts long-term, you should consider migrating them now;如果您关心长期使用 Python 2.7 脚本,您应该考虑现在迁移它们; using unsupported software is only going to get harder over time.随着时间的推移,使用不受支持的软件只会变得越来越难。

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

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