Install Tensorflow in virtual environment python 2.7 - python

Please, how can i install Tensorflow in a virtual environment? I have used these commands but it doesn't work..
sudo -H pip3 install tensorflow --proxy https://XXX.XX.XX.X:3128
sudo -E pip3 install tensorflow --proxy https://XXX.XX.XX.X:3128
sudo -E pip install tensorflow --proxy https://XXX.XX.XX.X:3128
sudo -H pip install tensorflow --proxy https://XXX.XX.XX.X:3128
sudo pip install tensorflow --proxy https://XXX.XX.XX.X:3128
It resulted in:
Downloading/unpacking tensorflow
Cannot fetch index base URL https://pypi.python.org/simple/
These are my python and pip versions:
(venv)root#graphene-62:~/tensorflow# pip -V
pip 8.1.2 from /usr/local/lib/python2.7/dist-packages/pip-8.1.2-py2.7.egg
(python 2.7)
(venv)root#graphene-62:~/tensorflow# python -V
Python 2.7.6
After I tried pip install -U tensorflow, I got the following result:
Cannot uninstall 'six'
Then I tried pip install -U tensorflow --ignore-installed six, and with the tf version check I got:
(venv)root#graphene-62:~/tensorflow# python -c "import tensorflow as tf; print(tf.__version__)"
Illegal instruction (core dumped) (venv)root#graphene-62:~/tensorflow#
Is there another way to download and install Tensorflow?

Please make sure that your pip version is up to date with:
pip install -U pip
Then, as per the comments and edited question, execute:
pip install -U tensorflow==1.5.0 --ignore-installed six
This will ignore the six related error and the slightly downgraded tensorflow package will install and be useable without the Illegal Instruction error.
To check if the installation was successfull, execute:
python -c "import tensorflow as tf; print(tf.__version__)"

Recently, pip install tensorflow with python 2.7 might cause the error message:
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
You can instead install TensorFlow with:
pip install -U https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.14.0-cp27-none-linux_x86_64.whl
You can replace the URL of the wheel with some other URLs from https://www.tensorflow.org/install/pip
Same issue with tensorflow-gpu.

Related

probelm at installing channels(django), and importing it's inner packages(channels.layout)

I have the same problem.
pyhton(3.9.1).
using virtual environmnet (venv).
installed django.
updated:
setuptools: pip install --upgrade setuptools,
pip(20.3.3): py -m pip install --upgrade pip
wheel: python -m pip install --upgrade pip setuptools wheel
(latesed version for today(30/12/20)).
Tried to use: python -m pip install -U channels.
installed "Microsoft Visual C++ Build Tools"
Tried the self installing twisted: https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted
All done, but still not working.
Also tried pip install:
pip install pytype
pip install django-channels.
The django-channels, but when runnig on PyCharm, it recognize channels but not: channels.layers.
Can anyone help?
I managed to install it:
just removed python, and installed instead Anaconda 3.

pip install --upgrade pip isnt upgrading pip

I'm trying to upgrade pip on Centos 7. I pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7) installed.
When I run pip install --upgrade pip --user I get the following output:
Collecting pip
Using cached https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-8.1.2
You are using pip version 8.1.2, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
What I've tried
I've tried the following, which have all resulted in the same output and result as above:
pip install --upgrade pip --user
pip install -U pip --user --ignore-installed
pip install -U pip --user --ignore-installed --no-cache-dir
sudo yum update pip which returns
No Match for argument: pip
No package pip available.
No packages marked for update
sudo yum update python-pip which returns No packages marked for update
Observations
python -m pip --version outputs:
pip 19.3.1 from /home/deploy/.local/lib/python2.7/site-packages/pip (python 2.7)
pip --version outputs:
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
You need to update your PATH to include /home/deploy/.local/lib/python2.7/bin before /usr/lib/python2.7/bin if you want pip to resolve to the same location as python. Otherwise, python -m pip is the more proper usage pattern
Otherwise, you're looking at two completely separate python installations and pip is indeed upgraded in one of them
Note: Python2 is end of life, so probably best to remove the one in your home folder, anyway, and switch to using something like Pipenv or pyenv

How to install dlib for python on mac?

I'm getting an error when trying to install dlib on Python 3.7 on macOS with
pip3 install dlib
I have installed CMake, so that is not the problem.
I'm getting these error messages:
Failed building wheel for dlib
and
Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-install-ls2e_3mr/dlib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-record-hy3hu262/install-record.txt --single-version-externally-managed --compile"
failed with error code 1 in /private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-install-ls2e_3mr/dlib/
at the end in red. The reason I need dlib is to install face_recognition.
I think there's more to the error message and it's probably related to CMake, either it's not installed properly or it's not compatible with the pip3 install dlib.
I suggest using Homebrew to install Python3 (which includes pip3) and CMake. Homebrew manages the installation of packages, tools, libraries that might depend on system-related tools, paths, etc. It also prevents you from having to use sudo to install stuff on your system.
Install Homebrew
See the "Install Homebrew" section of https://brew.sh/
Basically:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Install Python3 (and pip3) using Homebrew
See https://docs.brew.sh/Homebrew-and-Python
See Homebrew's formula for the latest Python3 (python3.7, python3.8, python3.9)
Basically do one of the following:
$ brew install python#3.7 # or python#3.8 or python#3.9
$ brew install python#3 # get whichever is the latest version
Check Python installation
$ python3 -V
$ python3 -m pip -V
Install CMake using Homebrew
See https://formulae.brew.sh/formula/cmake
Basically:
$ brew install cmake
Check CMake installation
$ brew info cmake
$ cmake --version
Finally, install dlib with pip
$ python3 -m pip install dlib
If you don't want to use Homebrew (for some reason), you can try installing CMake for Mac directly using the installers (dmg or tar.gz) from here: https://cmake.org/download/.
Install Homebrew from here
A bunch of dependencies are needed for dlib:
brew install cmake
brew install boost
brew install boost-python
brew install dlib
pip3 install numpy
pip3 install scipy
pip3 install scikit-image
pip3 install dlib
If this does not work, try:
python3 -m pip install dlib
dlib is dependent on cmake so you need to install that first.
You just need to run following commands on your terminal:
$ brew install cmake
$ pip install cmake
$ brew install dlib
$ pip install dlib
You can install the conda-forge Dlib package by running
conda install -c conda-forge dlib
Conda-forge has made sure to resolve all the dependency conflicts, so I had no issues with the installation. They have pre-built binaries for Windows, Linux, and Mac OS, and Python 2.7 through 3.8. The current package (at the time of this writing) is based on Dlib v19.19.
$ pip3 install --upgrade pip
$ pip3 install global
$ pip3 install cmake
$ pip3 install dlib
$ brew install dlib
$ sudo pip install dlib
The only thing you need to do, I guess, is run pip3 install dlib with sudo.
sudo pip3 install dlib

Installing tensorflow on Anaconda

I have a linux machine to which i installed Anaconda.
I am following:
https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html
pip instaltion part.
To be more specific:
which python
gives
/home/user/anaconda2/bin/python
After which i entered:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
And after:
sudo pip install --upgrade $TF_BINARY_URL
However,
while trying:
python -c "import tensorflow"
I get an import error:
ImportError: No module named tensorflow
The 'sudo' makes pip install tensorflow outside the env. Try:
pip install --upgrade $TF_BINARY_URL
Just tested this on Ubuntu 14.04 w/ conda env, was able to reproduce (with sudo) and resolve issue (without sudo).
You can also check the "Using Conda" section of tensorflow.org. They list the below:
# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL
# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL
In anaconda, simply do:
for installation
conda install -c conda-forge tensorflow
for update/upgrade
# -f will force the current installation to upgrade
conda update -f -c conda-forge tensorflow

How to upgrade pip3?

I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it doesn't work when I upgrade it.
You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running pip3 install --upgrade pip.
It might be a good idea to take some time and read about virtual environments in Python. It isn't a best practice to install all of your packages to the base python installation. This would be a good start: http://docs.python-guide.org/en/latest/dev/virtualenvs/
To upgrade your pip3, try running:
sudo -H pip3 install --upgrade pip
Your pip may move from /bin to /usr/local/bin
To upgrade pip as well, you can follow it by:
sudo -H pip2 install --upgrade pip
Try this command:
pip3 install --upgrade setuptools pip
First decide which pip you want to upgrade, i.e. just pip or pip3.
Mostly it'll be pip3 because pip is used by the system, so I won't recommend upgrading pip.
The difference between pip and pip3 is that
NOTE: I'm referring to PIP that is at the BEGINNING of the command
line.
pip is used by python version 2, i.e. python2
and
pip3 is used by python version 3, i.e. python3
For upgrading pip3: # This will upgrade python3 pip.
pip3 install --upgrade pip
For upgrading pip: # This will upgrade python2 pip.
pip install --upgrade pip
This will upgrade your existing pip to the latest version.
The Problem
You use pip (the Python 2 one). Now you want to upgrade pip (the Python 3 one). After that, pip is the Python 3 one.
The solution
Use pip2 and pip3. This way it is explicit.
If you want to use pip, just check where it is (which pip) and change the link. For example:
$ which pip
/usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ which pip2
/usr/local/bin/pip2
$ sudo rm /usr/local/bin/pip
$ sudo ln -s /usr/local/bin/pip2 /usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
What worked for me was the following command:
python -m pip install --upgrade pip
pip3 install --upgrade pip worked for me
In Ubuntu 18.04, below are the steps that I followed.
python3 -m pip install --upgrade pip
For some reason you will be getting an error, and that be fixed by making bash forget the wrongly referenced locations using the following command.
hash -r pip
If you have 2 versions of Python (eg: 2.7.x and 3.6), you need do:
add the path of 2.x to system PATH
add the path of 3.x to system PATH
pip3 install --upgrade pip setuptools wheel
for example, in my .zshrc file:
export PATH=/usr/local/Cellar/python#2/2.7.15/bin:/usr/local/Cellar/python/3.6.5/bin:$PATH
You can exec command pip --version and pip3 --version check the pip from the special version. Because if don't add Python path to $PATH, and exec pip3 install --upgrade pip setuptools wheel, your pip will be changed to pip from python3, but the pip should from python2.x
This worked for me (mac)
sudo curl https://bootstrap.pypa.io/get-pip.py | python
If you try to run
sudo -H pip3 install --upgrade pip3
you will get the following error:
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
but if you upgrade using the suggested command:
pip install --upgrade pip
then, the legacy pip will be upgraded, so what I did is the following:
which pip3
and I located my pip3 installation (just in case the following command wouldn't upgrade the legacy pip. Then i changed to that directory and upgraded pip3 using the following commands: (your directory could be different)
cd /Library/Frameworks/Python.framework/Versions/3.8/bin
sudo -H pip3 install --upgrade pip
after this:
pip --version
will still show the legacy version, while
pip3 --version
will show pip 21.0.1

Categories