Install package from conda for a specific version of python - python

I'm relatively new on dealing with python libraries so it might be a stupid question but here is the detailed problem:
I'm working on Linux and trying to use a python program (ORF-rater) using python 3.7. Unfortunately, when I run the program, I get the following error:
ImportError: cannot import name 'maketrans' from 'string'
which I think is related to this issue. Therefore I want to use another version of Python (3.4 or 2.7 for instance) that will support this maketrans.
The program that I'm using also uses the Python package plastid, which I installed using Conda conda install -c bioconda plastid which I guess worked well.
However, it installed the package on python 3.7 only, and I can't find a way to install for python 3.4 (I tried others things as pip3.4 install plastid, but it did not work, most likely because I'm working on an university server and I don't have permission to do it).
In brief, how do I install a package using Conda for a specific version of Python (3.4)?

The following code creates an environment with a specific python version (2.7 since 3.4 was not an option), then you activate it and install the package you need.
conda create -n test python=2.7
conda activate test
conda install -c bioconda plastid
python
Then in Python, I did the following and got no errors
from string import maketrans

Related

How to install python library to specific environment (without conda)

Update update: json_lines is not supported by python versions < 3 - my issue had pretty much nothing to do with environments. I am now using 3.9.1 and all is gucci.
Update: After using which python in my jupyter notebook and in my Terminal, I see that they are both using the same environment. As such I am still at a loss as to why my notebook cannot find json_lines.
I have two python environments on my computer, a default one and one I have for running my jupyter notebook on. I am trying to install the library, json_lines to the latter environment. I am not used the Anaconda environment manager.
On my Mac's Terminal I used the general pip install command pip install json-lines, but when I try to execute the following line of Python import json_lines in my notebook, I still receive the following error ImportError: No module named json_lines.
As I suspect I am not installing to the correct environment, I tried installing the library from inside my notebook with the following, import sys; !{sys.executable} -m pip install jsonlines.
However, this has not changed my dilemma.
Is there some way I can specify from my Terminal which environment to install to? or is it likely I am encountering a different issue to what I suspect?
The package for json_lines in pip in json-lines. Hence you could install it as:
$ pip install json-lines
It may be appropriate to use an isolated python environment for your particular project if you want to use particular conda libraries but without the whole package. In this instance, you would be able to use virtualenv. This will allow you to create an isolated python environment.
$ pip3 install virtualenv
You can call virtualenv to create a virtual python environment with the working name e.g. myvenv.
$ virtualenv myvenv
From here, you can set your terminal to use this python version. If you are on *nix:
$ which python
/usr/bin/python
$ source myvenv/bin/activate
(myvenv)$ which python
/.../myvenv/bin/python
This article can help you out.
https://janakiev.com/blog/jupyter-virtual-envs/
You need to create a virtualenv which will be used by your notebooks.

How can I change between versions of python 3

I am trying to use tensorflow but my python is to recent. I have python3.7.2 and I need py3.6 in order to install and use tensorflow.
I have installed py3.6.8 but I still can't install it with pip. Is there a way of interchanging between versions of python to install/use tensorflow. Or is it to do with my pip version?
The error is:
Could not find version that satisfies the requirement tensorflow in versions:
The main problem is that I don't know how to get tensorflow. Can someone help me do this?
By far the best option will be to use Anaconda virtual environment. After you install Anaconda, use environments to manage different versions of Python:
Python 3.6.8:
conda create -n myenv python=3.6.8 tensorflow
Python 3.7:
conda create -n myenv python=3.7 tensorflow
Why am I saying it's best with Anaconda? Long story short, it can be (much) faster. Here's an article that discusses why.
Option 1:
Install multiple versions in separate directories, and then you run the python program with the Python version you want to use. Like so:
C:\Python26\Python.exe thescript.py
What virtualenv does is that it gives you many separate "virtual" installations of the same python version. That's a completely different issue, and hence it will not help you in any way.
Option 2:
Use Pythonbrew.
Once pythonbrew is installed:
#to install new python versions is as simple as:
pythonbrew install 2.7.2 3.2
#to use a particular version in the current shell:
pythonbrew use 3.2
#to uninstall:
pythonbrew uninstall 2.7.2

Problems with installing matplotlib in python 3.6

I'm trying to teach myself python, and I feel out of my depth. To start, I am working on a mac which already comes with python 2.7 installed.
I installed python 3.6 recently and have been using it to teach myself the basics. I'd like to eventually learn how to produce mathematical plots in python, and I know I will need the matplotlib package to do that.
Following some advice online, I was told that python3 already comes with pip installed, which is what I thought I should use to install matplotlib. The advice said I should type the following into the mac terminal:
python3.6 -m pip install matplotlib
I typed this, and it seemed like the package was installing, but I ended up getting some sort of error code that said:
Command "python setup.py egg_info" failed with error code 1 in [folder].
I tried opening IDLE and typing "import matplotlib", but I got the error: "no module named matplotlib". I also tried typing "import matplotlib.pyplot as plt", but I got the same error.
Based on further research and this youtube video, I've decided to just install miniconda in order to have access to the matplotlib package.
The problem is, I'm not sure if I should somehow be uninstalling whatever was installed when I ran the code above to install matplotlib. I've actually run that line of code 3 or 4 times. Should I remove anything before installing miniconda? Also, I am running python 3.6, while miniconda is listed on the website as being for python 3.5. Does this mean it won't work for my version of python?
Running pip like that would install packages system-wide. I'm guessing it's failing because you're not running as root (i.e. the administrator user). But wait! Don't try again as root! Instead of installing packages, do it in a virtual environment. First create it:
virtualenv myenv
This creates a directory called myenv with a bunch of stuff in it (so make note of where you run this command). Whenever you want to use the virtual environment (like straight away!) you first need to activate it:
. myenv/bin/activate
Don't miss out that dot (followed by a space) at the beginning! As the other answer says, the first thing you should do in it is upgrade pip:
pip install --upgrade pip
Now you're ready install whatever else you like:
pip install matplotlib
One last note: The virtual environment is tied to a particular Python version. By default it uses the system's Python 2.7 installation, so to use a different one you need to specify it when you create the virtual environment, like this (if that Python version is installed system-wide):
virtualenv -p python3.5 myenv
Or like this (if that Python version is not installed system-wide):
virtualenv -p /path/to/my/installation/of/python3.5 myenv
While the virtual environment is activated, you don't need to specify the particular path/version of Python. Just run it like this:
python
I also encountered many problems during my installation.
It seems that version 2 of matplotlib is not compatible with Python version 3.
Finally, I succeeded by specifying version 3 of matplotlib as follows with the following command:
sudo apt-get install python3-matplotlib
Reference from the Matplotlib website:
https://matplotlib.org/users/installing.html#building-on-linux
Try upgrade setup tools
--upgrade setuptools
or
easy_install -U setuptools
or upgrade pip
pip install --upgrade pip
I ended up downloading anaconda and using the python interpreter that comes with it, as anaconda comes with matplotlib and many other python packages of interest.
the pip command typically is for the Python 2. use pip3 instead to install the libraries in the python 3.X path
This should work
pip3 install matplotlib
The solution that work for me in python 3.6 is the following
py -m pip install matplotlib
Matplotlib files are downloaded in ~/.local/lib/python3.6/site-packages/ and not in /usr/lib/python3.6/ .
Try the command:
sudo cp -r ~/.local/lib/python3.6/site-packages/* /usr/lib/python3.6/

Does the python.org installer of python come with pip, and how do I use it?

I can download python 2.7.12 from python.org, and all python versions from 2.7.9 onwards are supposed to come with pip, but after installing it, using pip in the terminal does not work.
I am on macOS.
Have I installed pip, and if I have, how do I use it?
Here you have informations about pip:
https://packaging.python.org/installing/
normally python from python.org come with pip, maybe you should just update...
to update from terminal:
pip install -U pip setuptools
After when you need to install package, for example numpy, just do in a terminal:
pip install numpy
more informations here :
https://pip.pypa.io/en/stable/reference/pip_install/
you can also use conda install from anaconda as an alternative of pip :
http://conda.pydata.org/docs/get-started.html
Multiple instances of Python can coexist on your machine. Thus you could have installed Python 2.7.12 yet, when you call Python from terminal, you may be calling an older version.
To know which version you are using, type which python in terminal and look at its path. Then from Python in terminal, type
import sys
print(sys.version)
to get the exact version.
As Dadep says, I would recommend using conda to isolate your invironments if you have to play with multiple Python interpreters. Further conda simplifies 3rd party package installation process beyond doubt.

Installing TensorFlow in python 3.5 Anaconda distro conda env

What I did to try and solve this issue:
Using Mac OS X
Using Anaconda distro currently in my computer as the path /Users/hongshuhong/anaconda/
Used conda instead of virtualenv because of my distribution of python. I referred to the guide here and tried to download the same with conda's package manager: https://www.tensorflow.org/versions/master/get_started/os_setup.html#download-and-setup
Tensorflow worked correctly when I created an anaconda env using the command conda create --name ML python=2.7 anaconda to state I'm using 2.7 python, then used this command conda install -c https://conda.anaconda.org/jjhelmus tensorflow
gathered from the Anaconda Cloud to attempt to download it. It worked when I said
$ python
>>> import tensorflow as tf
...
However, it doesn't really fix the issue:
However, I want to use the 3.5 distribution of python, simply to keep up with the times and not use outdated pythons.
I attempted to download it using the same way in python=3.5, but it raised this error when I tried to run the command conda install -c https://conda.anaconda.org/jjhelmus tensorflow :
Hint: the following packages conflict with each other:
- tensorflow
- python 3.5*
Use 'conda info tensorflow' etc. to see the dependencies for each package.
And I ran the conda info tensorflow to see what was going on and I got:
Fetching package metadata: ....
Error: No packages found in current osx-64 channels matching: tensorflow
This is really frustrating me and I'm not sure what to do. If there's no work around for this, I think I'll have to use Anaconda's python 2.7 distribution for TensorFlow experiments. If anyone has any idea how to solve this compatibility issue(or some other kind of issue), I'd be extremely grateful. Thanks.
EDIT: I'm pretty sure TensorFlow supports 3.5 because in their documentations they say they support 2.7 python and 3.3+. If there were no clues as to whether they support 3.5, I would have already given up and used 2.7 by now.
The version of TensorFlow packaged here is version 0.5.
Python 3.x support was introduced in TensorFlow 0.6, so you need to figure out how to install the newest version into Anaconda.
Usually you can install packages into anaconda using pip, but I haven't succeeded with TensorFlow.
EDIT: I just noticed that the documentation hasn't updated the url to the pip-wheel.
To install tensorflow in python 3.5 via pip, use the following command:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.6.0-py3-none-any.whl
This links to ...tensorflow-0.5.0-py2-none-any.whl, which is an older version of tensorflow for python 2.x.
Tensorflow get started page link.

Categories