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.
Related
I am creating a conda env with conda create -n env python==3.8. But when I activate it and do python -V, it shows Python 3.6.8. Outside of the activated conda env python -V outputs Python 3.8.13.
I've gone through similar issues but none of the advice helps. I am desperate and mad :D
How is your Anaconda's Version?
1.
You must use "Anaconda Prompt (Anaconda3)" into command line,
and try "conda update --all", update your Anaconda.
2.
Did you install Python 3.6.X in your computer and update it?
If yes, this is why you at Outside see the python -V =3.6.13
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 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.
I installed Miniconda3 on Ubuntu 16, and used the command
conda create -n py37 python=3.7
to create an env, and use command conda activate py37 to activate the env. But when I use command python --version to check my Python version, it show the version of Python is 3.5.2. So I try to create another env with Python 2.7, but after I activate this env, the version of Python is still 3.5.2.
Debugging
When I type type python, it shows python is aliased to '/usr/bin/python3.5.2'. Then by using the command to edit the .bashrc file, I found that there is a line of statement
alias python='/usr/bin/python3.5.2'
so I tried to change to
alias python='/home/vagrant/miniconda3/envs/django-judge/bin/python'
where the Python version of the env is 3.7. Then when I type type python again, it returns that python is aliased to '/home/vagrant/miniconda3/envs/django-judge/bin/python'. But now, under all envs, the Python version has become Python 3.7.
Remove the alias altogether: it is not compatible with Conda to alias python.
I am relatively new to Python and trying to figure out how to set up my different implementations of Python. To run different packages, I have multiple installations of python 2.7 and 3.6, both 32-bit and 64-bit. For example, I run some GIS software that uses its own implementation of python (OSGEO4W) that I run from the installation location (32-bit Python 2.7). This python executable has a package (otbApplication), that doesn't really install from pip or conda. However, I mainly run python (also 32-bit Python 2.7) from Anaconda. When I am running from Anaconda, is there a way to have otbApplication and other libraries in OSGEO4W implementation of Python available?
Once you have anaconda up and running you can use following process to install anaconda equivalent of virtual environment.
Make sure you are able access anaconda from your current folder
(base) C:\Users>conda -V
conda 4.4.7
Lookup python version available to be installed.
long list, truncated here
(base) C:\Users>conda search "^python$"
Loading channels: done
Name Version Build Channel
python 2.6.8 5 defaults
|
|
|
python 3.6.4 h6538335_1 defaults
Create virtual environment with selected python version
(base) C:\Users>conda create -n testVirtualEnv python=3.6.4 anaconda
Solving environment: done
## Package Plan ##
environment location: C:\Anaconda3\envs\testVirtualEnv
added / updated specs:
- anaconda
- python=3.6.4
|
|
#
# To activate this environment, use
#
# $ conda activate testVirtualEnv
#
# To deactivate an active environment, use
#
# $ conda deactivate
Activate virtual environment
Notice context changed from (base) to (testVirtualEnv)
(base) C:\Users>conda activate testVirtualEnv
Test to check python version in virtual env.
(testVirtualEnv) C:\Users>python -V
Python 3.6.4 :: Anaconda custom (64-bit)
Install a package in virtual env
(testVirtualEnv) C:\Users>conda install -n testVirtualEnv openpyxl
Solving environment: done
## Package Plan ##
environment location: C:\Anaconda3\envs\testVirtualEnv
added / updated specs:
- openpyxl
|
|
Executing transaction: done
Deactivate running environment
Notice context changed to (base)
(testVirtualEnv) C:\Users>conda deactivate
(base) C:\Users>
Remove and delete virtual Env
(base) C:\Users>conda remove -n testVirtualEnv --all
Remove all packages in environment C:\Anaconda3\envs\testVirtualEnv
Proceed ([y]/n)? y
(base) C:\Users>
You can research further commands at official documentation site.