I am trying to create a new conda Python 2.7 environment.
For this purpose I am typing this in terminal:
conda create -n my_env_name python==2.7
After activating created environment (conda activate my_env_name) and checking Python version (python --version) I am getting Python 3.10.2
No matter which Python version I am trying to use in the new environment I am always getting Python 3.10.2 answer when checking the Python version.
Any idea what is wrong and how to solve this?
(I am working on iMAC, Chip Apple M1, macOS Monterey 12.1)
(After doing the same on my old machine everything works fine and after checking the Python version in a newly created environment I am getting Python 2.7.18.)
Here are some additional info.
When env is activated commands:
which python gives- /opt/local/bin/python
type python gives- python is /opt/local/bin/python
echo $PATH gives- /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros/.iraf/bin:/opt/anaconda3/envs/py27/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin
When env is not activated commands:
which python gives- /opt/local/bin/python
type python gives- python is /opt/local/bin/python
echo $PATH gives- /opt/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/uros/Desktop/iraf-main/unix/hlib/ecl.sh://Users/uros/.iraf/bin:/opt/anaconda3/bin:/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin
After running conda list output is this:
I had the same problem with my M1 Mac.
As it turns out when working with python versions below 3.8 according to this post here there is no support for running osx-arm64. They go into the details on how to fix this.
You can also follow this blog post from Danny Cunningham How to Manage Conda Environments on an Apple Silicon M1 Mac
Manage both ARM64 and x86 Python environments using conda
in your case it should be something like:
CONDA_SUBDIR=osx-64 conda create -n my_env_27_x86 python=2.7
I hope this helps,
TL;DR With conda3, specify the Python 2.7 version fully, e.g., 2.7.18.
When I tried to reproduce your command in my own conda3 environment, I got this error:
PackagesNotFoundError: The following packages are not available from current channels:
- python==2.7
However, when I specified the version of Python 2.7 fully, it worked for me:
conda create -n p27 python==2.7.18
conda activate p27
python --version
shows that Python 2.7.18 is the default Python in that environment.
Alternative: use conda2
With Anaconda3/Miniconda3, the default Python will be Python 3.x, whereas with Aanconda2/Miniconda2, the default Python would be Python 2.7.x. On your old machine, you might have had conda2 installed, which would explain why it worked.
Thanks to #FlyingTeller for pointing out conda2 is not necessary, though.
Related
I recently got a new M1 MacBook - first time ever using a Mac - and immediately downloaded Miniconda to get it set up for some Python work.
I created some virtual environments (e.g. conda create -n myenv python=3.8) but when active, the python command defaults to Mac's Python 2.7, preventing me from running scripts from the command line in VS Code. For example:
conda activate myenv
(myenv)% which python
/usr/bin/python
where shows me the default 2.7 installation and the correct virtual environment version, but I can't access it.
(myenv)% where python
/usr/bin/python
/Users/user/miniconda3/envs/myenv/bin/python
Any idea how to get VS Code to find the proper Python version? It seems to work from the built in terminal, just not VS Code.
OS: Monterey 12.2.1
VS Code: 1.65.0
Miniconda: 4.10.1
Could you try to take advantage of python3 instead of python in the MacOS?
Or you can try to rename the python.exe to something others, such as python2.7 under the /usr/bin/python?
So the problem is, that in windows, you can change the path, but in mac there is this thing, that if you don't select the version, for example:
sudo python test.py
It will run Python 2.7, because it is installed, and it runs the lowest installed version. So try using
sudo python3 test.py
or specify the version in the terminal
sudo python3.8 test.py
I have created a virtual environment using anaconda in VS. When the environment is active. I check the version using python --version, it gives the following output Python 3.9.9, whereas when I use which python and check the version from the path /usr/bin/python --version I get a different version Python 2.7.18. Why is that happening, and which version does the environment use?
Once your virtual environment is activated the python command will use the python version from your venv (located in path/to/.venv/bin/python).
which python and /usr/bin/python forces the use of the python version installed in /usr/bin/python which in your case seems to be version 2.7.18. If you want to change your default Python version (the one thats used with python without a venv being active) you can use sudo ln -s /usr/bin/python /usr/bin/python3.9.
I created conda ennviroment with python 3.6, but unfortunately this env uses python 2.7 . Why? How can i fix it?
I think i could have some alias for python 2.7, but where should i try to find it and how should i change this?
$ conda create --name nn2019 python=3.6 numpy=1.13.3 scipy=1.1.0
matplotlib tqdm scikit-learn=0.20.0 jupyter notebook
# ...
(base) jan#MacBook-Pro-Jan-2 ~
$ conda activate nn2019
(nn2019) jan#MacBook-Pro-Jan-2 ~
$ python --version
Python 2.7.15 :: Anaconda, Inc.
(nn2019) jan#MacBook-Pro-Jan-2 ~
$ conda deactivate
As you can see there is still python 2.7 instead of python 3.6, what should i do?
If you are using Linux OS then you have to export the path of the conda environment then you will be able to use python3.x. Use
export PATH="/Anaconda3/bin:$PATH"
before running python command. Also you can include this path to .bashrc file for permanently active this conda environment.
After activating my anaconda Python 3.6 environment with
source activate py36
if I type
python
I go into python 3.6, as expected. But if I type
ipython
I go into an ipython environment based python 3.5.5, which is the same python version I get using
source activate base
and then
python
How can I get into an ipython environment using my anaconda-supplied python 3.6 interpreter? I have updated my anaconda environment with
conda update anaconda
and
conda update conda
Doing so does not help.
EDIT:
I hadn't realized that I had to install ipython separately for the python 3.6 environment; I'd thought it was a default part of anaconda. So
conda install ipython
after
source activate py36
did the trick. It doesn't seem optimal that after activating a particular environment, ipython may bring up a completely different anaconda-based environment. I'd prefer it to simply cause a "command not found" error. Bringing up the wrong environment without making it very obvious that that is happening could lead to confusion or problems.
I hadn't realized that I had to install ipython separately for the python 3.6 environment; I'd thought it was a default part of anaconda. So
conda install ipython
after
source activate py36
did the trick.
Have you done hash -r since entering the conda environment? Bash can cache paths to executables, so sometimes it doesn't use the one reported by which. Running hash -r resets the cache
Maybe you need also to update ipython conda update ipython
I'm trying to upgrade my python to 2.7.11 on Ubuntu 15.10, by following the guides here
http://tecadmin.net/install-python-2-7-on-ubuntu-and-linuxmint/
http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html
But after, when I try and reopen terminal, and type in python it still shows the version is 2.7.10
Does anyone know why this is the case?
The post you've linked says explicitly in the first sentence: "you should not touch the Python version of the system." i.e., /usr/bin/python should remain the same and therefore if /usr/bin is earlier in your $PATH envvar than the path to the newly installed python version then python invokes /usr/bin/python and you see the old version.
To install/manage multiple minor python versions, you could use pythonz or similar tools (such as pyenv):
$ pythonz install 2.7.11 # to install 2.7.11 version
$ $(pythonz locate 2.7.11) # to start the corresponding version
You could create a virtualenv using the desired python version (using virtualenvwrapper's command):
$ mkvirtualenv -p $(pythonz locate 2.7.11) py2.7.11
python will refer to 2.7.11 version inside the virtual environment.