Linking to python libraries from different python executables on Windows 10 - 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.

Related

Conda unable to create different Python version environment

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.

pyenv global interpreter not working on windows10

I have just installed pyenv following the installation guide pyenv-win, things goes smoothly, but i could not make the pyenv global python as the global interpreter
I have rehashed after installation using pyenv rehash
PS D:\> pyenv versions
3.5.1
3.6.2
3.7.7
* 3.8.2 (set by C:\Users\xxx\.pyenv\pyenv-win\version)
results
> python --version
> 3.8.4
# expected
> 3.8.2
therefore, I am not able to use virtualenv with the pyenv installed python interpreter
virtualenv py382-djangodev --python=3.8.2
The path 3.8.2 (from --python=3.8.2) does not exist
I had the same issue which I finally solved:
1 - Uninstall Python (your current version when you type the command python -V)
2 - Install pyenv-win and add it to the PATH (here are some optional steps to install it via chocolatey, which adds it directly to the PATH)
2.2 - Install chocolatey
2.3 - In an administrator powershell run: choco install pyenv-win
3 - Start menu (windows key) -> Manage application execution aliases -> disable aliases related to python
4 - install the desired python version via pyenv: pyenv install DESIRED VERSION NUMBER
5- run pyenv rehash
6 - set it as global pyenv global DESIRED VERSION NUMBER
7 - you sould see the desired version by running the command python -V
In windows NT, the PATH variable is a combined result of the system and user variables:
The Path is constructed from the system path, which can be viewed in
the System Environment Variables field in the System dialog box. The
User path is appended to the system path
Shims PATH are defined in the user variables, so make sure your host python interpreter path is not defined in your system path
Deinstalling everything connected to python (except pyenv) and using pyenv only worked for me.

Miniconda update to new bash session

I have miniconda installed in my mac system. Back when I was installing I had downloaded the python 3.6 mac OS 64-bit (bash installer) from https://docs.conda.io/en/latest/miniconda.html
currently, there is python 3.7 bash session is available, I tried to install the latest bash after downloading with the below command,
bash Miniconda3-latest-MacOSX-x86_64.sh
after the license process and directory set to my old one (in the home directory) I see the error
ERROR: File or directory already exists: '/Users/xxxxxxxxxx/miniconda3'
If you want to update an existing installation, use the -u option.
What am I missing here. My primary reason to update is to update the python version. Since with "conda update conda" I only get python update of the 3.6 series. I want to update to 3.7 series of python.
Thanks.
There is no need to update Miniconda to change the Python version.
If you want to use a different Python version for certain projects, create new conda environments. Each conda environment can use a different Python version, and it is completely independent of the Python version in the base environment.
conda create -n myenv python=3.7
If you want to change the Python version of the base environment, use
conda install -n base python=3.7

Conda enviroment keep using python 2.7 instead of python 3.6

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.

How to run a package within the Anaconda environment?

I am a beginner, and trying to run a package, Trimmomatic, that is located within the Anaconda environment. I have tried to extensively google how to actually run a program within the environment and I cannot find anything. I usually code in bash so this is all new to me. Any help would be fantastic!
I am able to load the environment:
module load anaconda/2-4.2.0_cent
source activate base
But I have no idea how to get the package to run.
Thanks in advance!
When you install anaconda you're given the option to add it to your $PATH, and the default option is no.
Putting the anaconda directory in your path is a necessary first step, as this allows you to use the conda command which gets used a bunch.
I'm going to assume you installed anaconda to /home/me/anaconda3/. If you installed Anaconda2, change anaconda3/ to anaconda2/.
First off, do the following:
~$ [export] PATH="/home/me/anaconda3/bin:$PATH"
~$ conda --version
conda <X.Y.Z>
After you've confirmed conda is in your path, you'll already have access to the base env, but you can double-check with:
~$ conda env list
# conda environments:
#
base * /home/me/anaconda3
~$ which python
/home/me/anaconda3/bin/python
If you want to create a new venv, conda makes that extremely easy:
conda create python=2.7 -n py27env
Solving environment: done
## Package Plan ##
environment location: /home/me/anaconda3/envs/py27env
added / updated specs:
- python=2.7
The following packages will be downloaded:
package | build
---------------------------|-----------------
wheel-0.31.1 | py27_0 62 KB
python-2.7.15 | h1571d57_0 12.1 MB
certifi-2018.8.13 | py27_0 139 KB
pip-10.0.1 | py27_0 1.7 MB
setuptools-40.0.0 | py27_0 583 KB
------------------------------------------------------------
Total: 14.6 MB
The following NEW packages will be INSTALLED:
ca-certificates: 2018.03.07-0
certifi: 2018.8.13-py27_0
ncurses: 6.1-hfffgggg474d3e_0
openssl: 1.0.2p-h14c325_0
pip: 10.0.1-py27_0
python: 2.7.15-h1571e57_0
readline: 7.0-ha6073c88_4
setuptools: 40.0.0-py27_0
wheel: 0.31.1-py27_0
zlib: 1.2.11-ha838bed_2
...
Proceed ([y]/n)?
Now just press yes, conda will do it's thing, and you'll get a little prompt about how to use source activate, and you're good to go!
For completeness, here's a couple more lines of bash to double-check:
~$ source activate py27env
(py27env) ~$ which python
/home/me/anaconda3/envs/py27env/bin/python
(py27env) ~$ conda env list
~$ conda env list
# conda environments:
#
base /home/me/anaconda3
py27env * /home/me/anaconda3/envs/py27env
Hope this helps!
Type conda list to verify that the package you want to run is installed in the current environment. If you are not in the correct environment, type conda activate env_name (where env_name is the name of the environment you want to activate).
If the package you want to run is listed when you type conda list, then you can run it directly. Try by just typing the package name. If not, try python -m package_name.

Categories

Resources