How to install tensorflow-gpu for both python2 and python3 - python-3.x

I already have installed tensorflow 1.2, CUDA 8.0 and CuDNN 5.1 for python2.7. Now I want to use it for python3.5 but importing tensorflow fails. How do I install tensorflow for python3 again. And do I have to do the CUDA and CuDNN episodes again?

You can create separate environment for python 2 and 3. Thus, you can easily install corresponding tensorflow versions. Remember you have to install everything separately on virtual environment once cuda and cudnn are installed on your system as per the instructions on Tensorflow webpage: https://www.tensorflow.org/install/install_linux
Although I would preferably keep both the envs separate but I tried to install both the versions in the same environment and it works.
My system configs are - CUDA - 8.0, CuDNN -7.1 and I tried installing Tensorflow 1.4.0.
# First, I created virtualenv for python2 as:
virtualenv --system-site-packages tf3n4 # tf3n4 is env name
# Then, I installed virtualenv for python3 with same name, it will not override python2 but it will create a seperate python3 bin.
virtualenv --system-site-packages -p python3 tf3n4
# go to your env (it's in my home directory)
source ~/tf3n4/bin/activate
Now you can check for both pythons by which python2 and which python3, this will be in your env path but not on the local machine python. For example: I got this /home/USERNAME/tf3n4/bin/python2 and /home/USERNAME/tf3n4/bin/python3.
#Now, install tensorflow for python 2:
python2 -m pip install --upgrade tensorflow-gpu==1.4
# install tensorflow for python 3:
python3 -m pip install --upgrade tensorflow-gpu==1.4
Once, you are done, you can run any python just by mentioning it:
python2 or python3 before running any code on terminal

If you have already installed tensorflow 1.2, CUDA 8.0 and CuDNN 5.1 for python2.7. Then you can:
yum install python3-pip
(now you have python3 and pip3, however the python version may not be 3.5)
python3 -m pip install --upgrade tensorflow-gpu==1.2
(make sure the installed version is exactly same as that of python2)
I made it after these two steps.

Related

how to install latest version of python and pip in arch linux?

My default operating system is ArchLinux and the Python version installed on it is 3.1.
I installed version 3.9 using aur, but I do not know how to systematize this version of Python by default and install pip for it, because when I try to use pip, I get this message:
$ python3.9 -m pip
/usr/bin/python3.9: No module named pip
Pip should be installed normally, and if not, there should be a package for pip, but if you cannot install it for whatever reason, installing pip can be done via the ensurepip module:
python -m ensurepip
Reference the documentation for more information.

Unable to install tensorflow using conda with python 3.8

Recently, I upgraded to Anaconda3 2020.07 which uses python 3.8. In past versions of anaconda, tensorflow was installed successfully. Tensorflow failed to be installed successfully in this version.
I ran the command below;
conda install tensorflow-gpu
The error message that I received is shown below;
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow-gpu -> python[version='3.5.*|3.6.*|3.7.*|>=3.7,<3.8.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0|>=2.7,<2.8.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
The following specifications were found to be incompatible with your CUDA driver:
- feature:/win-64::__cuda==11.0=0
Your installed CUDA driver is: 11.0
Is there a conda command with the right parameters to get tensorflow installed successfully?
UPDATE:
TF is now compatible with Python 3.8
Tensorflow is not compatible with Python 3.8. See https://www.tensorflow.org/install/pip
You need to downgrade your python version :
conda install python=3.7
Create an environment with python 3.7 and then activate it:
conda create -n p37env python=3.7
conda activate p37env
And install tensorflow.
This worked for me, and found out the answer from the Anaconda user guide (under how to use a different python version: https://conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python )
From the requirement page:
Python 3.8 support requires TensorFlow 2.2 or later.
So there is a verison of Tensorflow compatible with python 3.8.
The problem is that TensorFlow 2.2.0 is not available through conda on Windows, this should be the reason why you get PackagesNotFoundError when running
conda install tensorflow=2.2
EDIT 15/03/21
Tensorflow 2.3.0 is compatible with Windows
i think we have two options here
pip install tensorflow
or we can use another env of anaconda such as like this below
conda create -n tf tensorflow pydotplus jupyter
conda activate tf
Actually you can directly use pip inside anaconda prompt, after I tested it, I found the conda is capable with pypi, first run the anaconda prompt with administrator permission (in windows), then enter "conda update --all" to make sure all the packages are latest, finally enter "pip install tensorflow" to install (the new version of tensorflow already includes tensorflow-gpu).
Then using VS code to open an ipynb and run
import tensorflow as tf
tf.test.gpu_device_name()
everything looks good.
For more info please refer to Anaconda official docs: https://docs.anaconda.com/anaconda/ .
Latest development for tensorflow installation on anaconda.
https://anaconda.org/anaconda/tensorflow
https://anaconda.org/anaconda/tensorflow-gpu
9 days ago, Anaconda uploaded a new tensorflow v2.3 package. Anaconda3 2020.07 (uses python v3.8) users can easily upgrade to tensorflow v2.3 with the following commands;
conda install -c anaconda tensorflow
conda install -c anaconda tensorflow-gpu
I have personally tested that the installation worked successfully.
The other answers for this question have now become obsolete.
Expanding upon William's answer here with more explicit instructions and caveats. Pip is the recommended way to install latest version of tensorflow as per tensorflow's installation instructions -- "While the TensorFlow provided pip package is recommended, a community-supported Anaconda package is available."
Here is the code that uses pip to do the installation in a Conda environment:
conda create -n env_name python=3.8
conda activate env_name
conda install pandas scikit-learn matplotlib notebook ##installing usual Data Science packages that does include numpy and scipy
pip install tensorflow
python -c "import tensorflow as tf;print(tf.__version__)" ##checks tf version
In general, we should be careful while mixing two package managers (conda and pip). So, it is suggested that:
Only after conda has been used to install as many packages as possible
should pip be used to install any remaining software. If modifications
are needed to the environment, it is best to create a new environment
rather than running conda after pip.
For an example, if we would like to install seaborn in the just created env_name environment, we should:
conda create --name cloned_env --clone env_name
conda activate cloned_env
conda install seaborn
Once we check the cloned_env environment is working fine, we can delete the env_name environment.
I was running into the same issue in conda prompt for Python 3.8.5 and fixed it using a Python wheel instead. Here are the steps:
Open conda prompt and install pip if you don't have it already: python -m pip install --upgrade pip
python -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.4.0-cp38-cp38-win_amd64.whl
Note: If you need a CPU specific tensorflow, use this wheel: https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.4.0-cp38-cp38-win_amd64.whl
I just downgraded python to 3.7 as tf is not avialable to 3.8 version also I cannot use virtualenv for code that's why
The only working answer for me is:
conda install -c conda-forge tensorflow
It appears that tensorflow 2.5 on GPU has issues with spyder. So, I made new environment and installed tensorflow gpu as suggested by anaconda. Now I have to use either prompt or jupyter . At least it works
For macos users I suggest create an environment with python 3.7 and install tensorflow there.
You can run these commands too:
conda create -n new_env_name python=3.7
conda activate new_env_name
I had a similar problem in Anaconda Spyder. Here was my solution (In the Anaconda Console):
conda install pip
pip install tensorflow ==2.2.0

Can not use weka.core modules after successfull installation of python-weka-wrapper "No module named 'weka.core'"

I've installed python-weka-wrapper with its all dependencies like the following command shows:
sudo -H pip3 install python-weka-wrapper3
Requirement already satisfied: python-weka-wrapper3 in /usr/local/lib/python3.6/dist-packages/python_weka_wrapper3-0.1.7-py3.6.egg
Requirement already satisfied: javabridge>=1.0.14 in /usr/local/lib/python3.6/dist-packages (from python-weka-wrapper3)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages/numpy-1.17.0-py3.6-linux-x86_64.egg (from python-weka-wrapper3)
but, when I try to import weka.core.converters I get the followin error :
No module named 'weka.core'.
And moreover, I can find all of these modules in the directory
/usr/local/lib/python3.6/dist-packages/python_weka_wrapper3-0.1.7-py3.6.egg/weka
I can lso import weka.core.converters with python2.7, ,but I really need to use it with python3.
My machine infos:
OS: Ubuntu 18.0.4
python : 3.6.8 & 2.7.15
I'm not sure what you're doing wrong in your install, but here are the steps that I performed to get python-weka-wrapper installed for Python 2.7 and 3.6, on a freshly installed (and fully up-to-date) Ubuntu 18.04.1:
First, ensure to have pip installed and you can compile source code:
sudo apt-get install python-pip python3-pip virtualenv build-essential
Though Oracle JDK is recommended, you can get it to work with OpenJDK as well, just make sure to install the sources as well:
sudo apt-get install openjdk-8-source openjdk-8-jdk
I'm not a big fan of Anaconda, as I find it overkill, especially since virtualenv does things in a much leaner, cleaner and faster way. The instructions below create directories (pww27 and pww36 in your current directory), which you can simply delete, if you no longer require these virtual environments.
But, I've also listed instructions on how to use Anaconda further below.
Each of the virtual environments will run a test command: import the jvm module, start and stop the JVM, using python -c "...", to check whether the environment is working. This command will generate output similar to the following (paths will be different, of course):
DEBUG:weka.core.jvm:Adding bundled jars
DEBUG:weka.core.jvm:Classpath=['/home/fracpete/pww36/lib/python3.6/site-packages/javabridge/jars/rhino-1.7R4.jar', '/home/fracpete/pww36/lib/python3.6/site-packages/javabridge/jars/runnablequeue.jar', '/home/fracpete/pww36/lib/python3.6/site-packages/javabridge/jars/cpython.jar', '/home/fracpete/pww36/lib/python3.6/site-packages/weka/lib/python-weka-wrapper.jar', '/home/fracpete/pww36/lib/python3.6/site-packages/weka/lib/weka.jar']
DEBUG:weka.core.jvm:MaxHeapSize=default
DEBUG:weka.core.jvm:Package support disabled
OK, let's create the virtual environments and test them:
1. virtual environment for Python 2.7 (virtualenv):
virtualenv -p /usr/bin/python2.7 pww27
pww27/bin/pip install numpy
pww27/bin/pip install javabridge
pww27/bin/pip install python-weka-wrapper
pww27/bin/python -c "import weka.core.jvm as jvm; jvm.start(); jvm.stop()"
2. virtual environment for Python 3.6 (virtualenv):
virtualenv -p /usr/bin/python3.6 pww36
pww36/bin/pip install numpy
pww36/bin/pip install javabridge
pww36/bin/pip install python-weka-wrapper3
pww36/bin/python -c "import weka.core.jvm as jvm; jvm.start(); jvm.stop()"
3. virtual environment for Python 2.7 (anaconda3-2019.07):
conda create -n pww27 python=2.7
conda activate pww27
pip install numpy
pip install javabridge
pip install python-weka-wrapper
python -c "import weka.core.jvm as jvm; jvm.start(); jvm.stop()"
conda deactivate
4. virtual environment for Python 3.6 (anaconda3-2019.07):
conda create -n pww36 python=3.6
conda activate pww36
pip install numpy
pip install javabridge
pip install python-weka-wrapper
python -c "import weka.core.jvm as jvm; jvm.start(); jvm.stop()"
conda deactivate

How to install xlrd in python3 library

I am trying to install xlrd to read Excel files in python.
I have tried this: pip install -U pip setuptools. My macOS Mojave 10.4.3 has Python 2.7 which is where the default install goes to. But I have also installed Python3.7. How do I get pip install to my 3.7 directory?
I am on Mac machine(Catalina -version 10.15.5) and below pip3 command worked for me.
pip3 install xlrd
python version : 3.7.6
OS : Mac-Catalina(10.15.5)
Thanks to #Tapan Hegde, pip3 install xlrd worked from me, after installing the pip3, like this:
sudo apt update
apt install python3-pip
pip3 install xlrd
I reckon the easiest/cleanest solution would be to use a tool that isolates your python environment, such as virtualenv
Once installed, create a virtual env by specifying which version of python you want to use:
$> virtualenv -p python3 env
Note: puttin python3 directly works only for mac, with linux, you must specify the absolute path or your python binary.
And then 'activate' your environment:
$> source env/bin/activate
From here, any python or pip command you use will use python3.
$> pip install xlrd
Virtualenv has the advantage of not 'polluting' your local python installation, your can manage your pip modules installed more easily.
If you want more detail on how it works and the other alternatives, check this post
When pip install xlrd not work and in computer is still old version, then try do it with current version, for example pip install xlrd==2.0.1.
The current versions are here

Use or install different versions of python3 pip

I'm trying to install packages for my python 3.5.0 versus my python 3.4.3
I can run both by typing either python3.4 or python3.5
I have pip2 and pip3. I also ran the script sudo easy_install3 pip, which made me be able to use pip3.4 But I am still having trouble installing modules for python3.5. pip3 just installs for python3.4
I am looking to install termcolor for python3.5 and I am having no success. Can anyone help?
I am on Windows, and you appear not to be, but maybe the following will help.
If pip is in your system's equivalent of python35/Lib/site-packages, then python3.5 -m pip should run pip so that it installs into the 3.5 site-packages.
If you do not have pip in the 3.5 site-packages, copy its directory, along with its dependencies (pip....dist-info/, setuptools/, setuptools....dist-info/, and easyinstall.py) from the 3.4 site_packages.
Or, if pip3 or even pip3.4 is in python35/Scripts, run it with its full path name so you are not running the 3.4 version.

Resources