Command line conda with 2 anaconda installation - python

To make easier migration, 2 Anaconda versions have been installed on Windows:
Anaconda 27 and Anaconda 34
However, on the command line conda update ....,
how can I specify the right 'conda.exe'
apart from putting the full path for conda?

Recommended Solution - Using conda Environments
Instead of installing two different Anaconda version, I would recommend
to use conda environments. Create one for Python 2.7:
conda create -n py27 python=2.7
Now, you can activate it with:
activate py27
the prompt will change to
(py27)
and:
(py27) conda install anaconda
will install all Anaconda packages.
Likewise, do it for Python 3.5:
conda create -n py35 python=3.5 anaconda
This will install all anaconda packages right away.
Solutions for Already Installed Multiple Anaconda Versions
If you already have installed two Anaconda versions these solutions might work for you.
Using two command line windows
You can set the PATH environmental variable.
In your first shell do:
set PATH=C:\path\to\conda2;$PATH$
and in your second:
set PATH=C:\path\to\conda3;$PATH$
Now conda should be the version you set with the PATH.
Using one command line window
You can a create two batch files that you put in your PATH:
conda2.cmd
C:\path\to\conda2\conda.exe
conda3.cmd
C:\path\to\conda3\conda.exe
Now conda2 should start the Python 2 and conda3 the Python 3 version.

Related

Switching between Python 3.7 and 3.8 under Anaconda

I have an Anaconda installation on Windows 10 primarily to run Jupyter Notebook and Spyder.
I find the Python runtime (python.exe) in 3 places after installation, viz:
D:\ProgramData\Anaconda3
D:\ProgramData\Anaconda3\pkgs\python-3.7.6-h60c2a47_2
D:\ProgramData\Anaconda3\pkgs\python-3.8.2-he1778fa_13
The python.exe under 1. and 2. are identical and run Python 3.7. 3. runs Python 3.8.
Questions:
What is the rationale of having two versions under pkgs (as in 2. and 3. above) but just one default version (as in 1.)?
The contents under the pkgs directory - are they complete Python installations?
What is the best way to make Jupyter Notebook pickup Python 3.8? It currently picks up Python 3.7 because the location 1. is in PATH. (That is, are the pkgs directories full installations)?
If I want to work with Python 3.9, is there a way to upgrade the current Ananconda to that extent? Or, do I have to delete the current Ananconda3 and install the latest Anaconda provided, of course it supports Python 3.9?
What is the rationale of having two versions under pkgs (as in II and III above) but just one default version (as in I)?
The contents under the pkgs directory - are they complete Python installations?
The pkgs folder is only a type of cache where packages that conda downloads and decompresses are kept so that they can be installed more quickly into new environments, so no they are not complete python installations ready to be used. There can only be one python version in one environment, in your case D:\ProgramData\Anaconda3\python.exe is the one that belongs to the base environment
If I want to work with Python 3.9, is there a way to upgrade the current Ananconda to that extent? Or, do I have to delete the current Ananconda3 and install the latest Anaconda provided, of course it supports Python 3.9?
To install a different python version into the current environment, simply do conda install python=<version>. You can use conda search python to check the available versions, or see on the website that the default channel has 3.9 as a newest version. However upgrading your base will most likely fail. Anaconda comes with a huge list of preinstalled packages and python 3.9 is too new, so that conda will not be able to resolve dependencies with newer python versions. The newest anaconda installer comes with python 3.8. only
What is the best way to make Jupyter Notebook pickup Python 3.8?
To have multiple python installations, use virtual environments (as there can only be one python version in one environment) which is very easy to use:
conda create -n py39 python=3.9
conda create -n py38 python=3.8
conda create -n py37 python=3.7
would create three environments that you can selectively activate with
conda activate py37 #or
conda activate py38 #or
conda activate py39
To use an environment, you need to activate it and then you can also install packages for that environment, e.g. to set up jupyter for one of them, simply do
conda activate py37
conda install ipykernel jupyter
python -m ipykernel install --user --name py37 --display-name "Python 3.7"
then you can start jupyter as you are used to and select Python 3.6 as the kernel.
Note that for each environment you will need to install all packages again, there is no cross-talk between them, so doing
conda activate py37
conda install numpy
will install numpy only to the py37 env, not to base, py38 or py39

Install packages with Conda for a second Python installation

I recently installed Anaconda in my Windows. I did that to use some packages from some specific channels required by an application that is using Python 3.5 as its scripting language.
I adjusted my PATH variable to use Conda, pointing to the Python environment of the particular program, but now I would like to use Conda as well for a different Python installation that I have on my Windows.
When installing Anaconda then it isn't asking for a Python version to be related to. So, how can I use Conda to install into the other Python installation. Both Python installations are 'physical' installations - not virtual in any way.
Uninstall the other python installation and create different conda environments, that is what conda is great at.
Using conda from your anaconda installation to manage packages from another, independent python installation is not possible and not very feasible.
Something like this could serve your needs:
Create one env for python 3.5 conda create -n py35 python=3.5
Create one env for some other python version you would like to use, e.g. 3.6: conda create -n py36 python=3.6
Use conda activate py35, conda deactivate, conda activate py36 to switch between your virtual environments.

How to install the specific version of Python with Anaconda?

I want to install Anaconda with Python Version 3.6.5. If I install Anaconda3-5.2.0, It install Python 3.5.1. Where to download the Anaconda with Python 3.6.5. The Big Data Scripts work only with Anaconda Python 3.6.5.
Anaconda Downloads
The Anaconda distribution with Python 3.6.5 was version 5.2.0.1 You can download this from the Anaconda distribution archive. If you do install from this, then make sure to update Conda immediately after installation:
conda update conda
However, I strongly recommend the following alternate solution as better practice.
Miniconda + Anaconda environment
Reasoning
What is installed in the base environment is relatively fixed once installed. Ultimately, you don't want to mess with your base environment, so best practice is to have the latest version there. Fortunately, you don't have to install a full Anaconda distribution, but rather can use a lightweight Miniconda (or Miniforge) distribution and create a secondary environment for the purpose of having an Anaconda Python 3.6.5 distribution. In the long run this will give you better stability.
Steps
Download and install Miniconda or a Miniforge variant. Once that is working...
Create your Anaconda env:
conda create --name my_env -c anaconda python=3.6.5 anaconda=5.2.0
Use your new isolated env:
conda activate my_env
[1] I determined this by running conda create -n foo --dry-run -c anaconda python=3.6.5 anaconda and then examining the version of the anaconda package that Conda ended up with in the solve.
Also try
conda install python=3.6.5
but you may encounter some incompatibility issues with other packages.
Alternatively, you may want to try creating a new environment. From the anaconda prompt, create a custom environment and specify the repository channel to find the version
conda create --name py365 python=3.6.5 --channel conda-forge
Activate the new environment
conda activate py365
However, the activation will not be permanent, and you will need to activate each time you start the anaconda prompt.
In your anaconda prompt, you can manually update your python to the latest version with :
conda update python
In case you are not familiar with it, anaconda prompt is installed to your computer when you install anaconda. Just make a search for it on your computer.
You can refer to this post : How do I upgrade to Python 3.6 with conda?

Importing a package installed with anaconda in virtual environment

I want to work with the python package holopy. Apparently you have to use conda to install it, so I first installed Anaconda 4.2.0 (since I'm using Python 3.5). I opened the virtual environment I normally use and installed holopy as they recommend on the official site:
conda install -c conda-forge holopy
Afterwards, when in the virtual environment I type conda list, holopy shows up. But when I type python3 and then import holopy, it says package not found. It does however work when I leave the virtual environment. I need it in the virtual environment though, how can I do that?
I'm not sure how well anaconda and virtual environments i.e.venv work together. If you're using anaconda anyway then I highly recommend using anaconda environments. Please go through this short tutorial about anaconda environments - you won't regret it.
Why it didn't work for you?
The conda command is available only in the base anaconda environment. So when you run the command - conda insall -c conda-forge holopy, it installed holopy in the base anaconda environment and it won't be available to you in your venv.
After looking at the documentation of holopy it seems probable that when they said virtual environment they actually meant anaconda virtual environment. Therefore the solution is to first create an anaconda virtual environment called holopy-env and then run the command conda install -n holopy-env -c conda-forge holopy.
A better way of doing things with Anaconda
I will also give you a quick and clean example of how to create an environment using anaconda. If you're using Anaconda then it would be wise to use it's environment management tools. Create an environment.yml file with the following contents:
environment.yml using conda-forge/holopy & python 3.6
name: holopy-env # any name for the environment
channels:
- conda-forge
dependencies: # everything under this, installed by conda
- python=3.6
- holopy
- pip: # everything under this, installed by pip
- future
How to install the environment?
conda create --force -f environment.yml
How to activate the environment?
source activate opencv-env
After activating the environment
You should be able to import holopy
Install pip packages using pip install <package>
Install conda packages using conda install -n holopy-env -c CHANNEL <package>
conda is a packaging tool and installer that aims to do more than what pip can do; handle library dependencies outside of the Python packages as well as the Python packages themselves. Conda also creates a virtual environment, like virtualenv does. For creating virtualenv with conda, use the following command:-
conda create -n yourenvname python=x.x anaconda
Use the following to activate the virtualenv in conda
source activate yourenvname
Then, you can install the packages in virtualenv using conda as:-
conda install -n yourenvname [package]
To Deactivate use:-
source deactivate
And to delete a no longer needed virtualenv, use :-
conda remove -n yourenvname -all
I know this is a bit late, but you don't need to use conda to install HoloPy. This is just the least technical option. Otherwise, you need to be able to compile HoloPy's fortran components yourself, which is fairly straightforward on Unix-based systems but complicated on Windows. Instructions can be found in HoloPy's documentation at https://holopy.readthedocs.io/en/latest/users/dev_tutorial.html.
We are also working on putting together a singularity container distribution of HoloPy. Let me know if this is of interest to you and I will make it a priority.

Installing python 3.6 , when I am already using Anaconda Python 2.7

I am currently using Anaconda2 .
python -V gives :- Python 2.7.11 :: Anaconda 4.0.0
Now I want to use Python 3.6 and i tried to update my python version using the following command in anaconda:-
conda install python=3.6
but this did not worked , because I work in a restricted environment MNC .
Two Options are available to me and I want to know which one should I follow
1> I can install Anaconda3 .
But if do that , do i need to uninstall already existing version of Anaconda I am using i.e Anaconda2 ? If not please tell me how will I choose which version of python to use in Spyder.
2> I can install Python3.6 .
If I take this option , I have no idea of what to do afterwards.
P.S.:- I am not very good at installation so please guide me in the easiest way possible.
Also if there is some other way , please share that too
are you able to create a new environment with the command:
conda create -n py36 python=3.6
?
if so, anaconda will create a new subfolder for this environment in the anaconda/envs folder named py36. in spyder you can go to tools->preferences->python interpreter and choose the python interpreter (python.exe if on windows) in that folder. to use pip and all in the commandline for that environment write:
if on linux/mac:
source activate py36
if on windows:
activate py36
then continue to do you installations and all.
Take a look at environments, which enable you to have multiple python versions and manage them seperately. The documentation can be found here
In short, just do:
conda create -n myenv python=3.6
to create an environment with python 3.6. You can enter it doing
source myenv
and then pip install any desired packages.
If you are using Anaconda and python, you just update it with:-
Open Anaconda Prompt type:-
conda update conda
conda update python
Check your python version python --version and conda version conda --version

Categories