0

So the default of anaconda is python 3.8, but you can invoke python2 by running python2 a_py_script.py. 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. 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.

I've tried pip2.7 install biopython and python2.7 -m pip install biopython to no avail. 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? (I did notice that conda list includes only 3.8 and no mention of 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. conda create --name py27test --clone base python=2.7 says too many 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?

Tom
  • 919
  • 3
  • 9
  • 22
  • Are you running the command python2 from the terminal/cmd prompt? Your Anaconda env should only have 3.8 on it, but you can still have python2 somewhere else. I'd say you should just bit the bullet and upgrade your scripts or make a new env in 2.7 in a standard way, otherwise you are inviting a disaster. Of course I guess that's exactly what the current answer is saying too, haha. – itwasthekix Mar 17 '21 at 16:30
  • Does this answer your question? [How do I install a package for different Python versions in Anaconda?](https://stackoverflow.com/questions/43707369/how-do-i-install-a-package-for-different-python-versions-in-anaconda) – merv Mar 17 '21 at 21:34

1 Answers1

0

You can't mix Python versions in a conda environment. You can call Python executables from outside your environment, but that's unadvisable for anything requiring dependencies. 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.

If you care about using your Python 2.7 scripts long-term, you should consider migrating them now; using unsupported software is only going to get harder over time.

Matt Thompson
  • 641
  • 3
  • 14