Tensorflow Update Forcing Python3.5 when 3.7 installed - python

I currently have Tensorflow 1.14.0 installed. I upgraded Python to 3.7 in order to get at least Tensorflow 1.15 if not 2.0. My python updates were successful:
pi#HCoreDEV:~ $ python --version
Python 3.7.0
pi#HCoreDEV:~ $ python3 --version
Python 3.7.0
Now, when I try
sudo pip install --upgrade tensorflow
I get the following (there are a LOT more lines, but they all say "requirement already satisfied" or "up to date"):
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already up-to-date: tensorflow in /usr/local/lib/python3.5/dist-packages (1.14.0)
NOTE that it defaults to the python 3.5 folder.... ????
BUT: If I try to check the VERSION of TF:
pi#HCoreDEV:~ $ python3 -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
pi#HCoreDEV:~ $ python -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
It doesn't even see ANY TF installed.
Here is my update-alternatives output:
pi#HCoreDEV:~ $ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
* 3 /usr/bin/python3.7 3 manual mode
Press <enter> to keep the current choice[*], or type selection number:
And finally, here is my sourced ~/.bashrc file's aliases for python and python3 for good measure:
alias python='/usr/bin/python3.7'
alias python3='/usr/bin/python3.7'
So WHY is it that with confirmed python3.7 installed and running, Tensorflow only looks at the 3.5 folder, sees an existing install that was running before I upgraded to 3.7, and says the requirements are satisfied?
When I just type "python" into my terminal window, this is the output:
pi#HCoreDEV:~ $ python
Python 3.7.0 (default, Feb 6 2020, 16:11:11)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Lastly, here is my sys.path output:
>>> import sys
>>> sys.path
['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
>>>
Need some help, I hope I've provided enough info to make the issue obvious to someone with a bit more experience than me.

The latest Python version on Stretch is 3.5. The command line tool pip calls the Python 3.5 Pip module. If you have another version installed and you want to install/update packages for that specific version, then you must use the correct Pip by running it like this (assuming python3 is the correct version or an alias):
$ python3 -m pip install --upgrade tensorflow
Or if you need sudo:
$ sudo -H python3 -m pip install --upgrade tensorflow
If you don't have Pip installed for that specific Python version you can run:
$ sudo -H python3 -m ensurepip

Related

How do I find and use my imported modules?

I am very new to python, and this is one of my first projects. I now use PyCharm, but started with Anaconda and jupyter notebook. When i try to import a module into my project, i get this error:
import stdiomask
stdiomask.getpass('Password: ')
/Users/Kristoffer/.conda/envs/Prosjekt_beginner/bin/python "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py"
Traceback (most recent call last):
File "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py", line 1, in <module>
import stdiomask
ModuleNotFoundError: No module named 'stdiomask'
After searching the internet for answers, I am still lost, but suspect it has something to do with my pythonpath. Anaconda might also have something to do with it. As I said I just started with python, so I do not know whether this is enough information to solve my problem, but this is what i did:
Checking if the module is installed with both pip and pip 3:
(base) KKWs-MBP-2:~ Kristoffer$ pip install stdiomask
Requirement already satisfied: stdiomask in ./opt/anaconda3/lib/python3.8/site-packages (0.0.6)
(base) KKWs-MBP-2:~ Kristoffer$ pip3 install stdiomask
Requirement already satisfied: stdiomask in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (0.0.6)
WARNING: You are using pip version 20.2.3; however, version 20.3.1 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m pip install --upgrade pip' command.
And then i checked which version of python I am using and got two different answers.
(base) KKWs-MBP-2:~ Kristoffer$ python
Python 3.8.3 (default, Jul 2 2020, 11:26:31)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
(base) KKWs-MBP-2:~ Kristoffer$ python3
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
I then typed in this in PyCharm and got:
import sys
print(sys.path)
/Users/Kristoffer/.conda/envs/Prosjekt_beginner/bin/python "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py"
['/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler', '/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python38.zip', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8/lib-dynload', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8/site-packages']
So As You Said You are using Anaconda So when you are doing pip3 install stdiomask or pip install stdiomask you are installing it on your real python enviroment & as you mentioned you are using anaconda enviroment,
so give this command conda install stdiomask
Or visit This Website And Read...
I Hope it Helped
Jai Hind Jai Bharat
Unfortunately, when using pip or pip3 to install packages, these are python modules, but also binaries, and using them like:
pip install <package>
or
pip3 install <package>
Doesn't explicitly tell you which interpreter pip is pointing to. However, executing a module using python -m <module> uses the python in your path, and is explicit. You've already seen that the pip -V site-packages is different than your interpreter's site-packages. The way to get around this is to use pip as a module:
python -m pip install <package>
Then you know that you are using the python that you currently have activated

Numpy module not found error vs code & jupyter notebook

unable to import numpy into my vs code project due to following error:
ModuleNotFoundError: No module named 'numpy'
I have already installed numpy with the following results:
sudo -H pip3 install -U numpy
Successfully installed numpy-1.19.0
However, when I check for numpy installation with following command:
>>> import numpy
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I have also tried to change the environment in VS code from 3.8.3 64-bit to 3.7.6 54-bit ('base':conda) but didn't get any better results.
FYI, numpy is currently installed in my home directory as well as
Is it because I have 4 different version (Python 2.7.17 64-bit, Python 3.6.9 64-bit, Python 3.7.6 64-bit & 3.8.3 64-bit) of Python installed on my Linux Mint Cinnamon OS?
Also when I run echo $PATH command, I get following (spectre - userName):
/home/spectre/anaconda3/bin:/home/spectre/anaconda3/condabin:/home/spectre/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Don't know if it is correct.
Appreciate help.
I have managed to resolve the issue with numpy installation.
The issue was with my python version 3.7 which was nested in anaconda directory and not at its default place.
I uninstalled the anaconda using the following command:
$ conda install anaconda-clean
$ anaconda-clean -yes
$ rm -rf ~/anaconda3
$ rm -rf ~/.anaconda_backup
Updated with alternatives command:
$ update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
$ update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
Now to list all the alternative installation:
$ update-alternatives --list python
and finally for the option to swap between different Python versions:
$ update-alternatives --config python
Selected the correct option for python 3.8 from the given prompt and done.
Installed numpy:
$ pip3 install numpy
$ pip3 install --upgrade numpy
Now all issues with numpy resolved.

How to use pip3 or pip in pyenv for virtual python I created?

1)I use multi -versions,but I when I use pyenv to shift to other version(installed by pyenv),I cant install any package like numpy and tensorflow.
lzw#resplendent-star:~$ python3
Python 3.8.1 (default, Apr 11 2020, 17:03:40)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> exit()
lzw#resplendent-star:~$ sudo -H pip3 install numpy
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages
you could see,3.8.1 is what I installed by pyenv,but I cant install numpy for it.
2)The worst thing,how could I use system default python?
You should make sure that you are using the correct pip to install your dependencies.
The quickest way is usually to try:
python3 -m pip install numpy
This makes sure that you are using the pip corresponding to the version of python that you want to use. However this method sometimes does not work on some Linux distributions that remove the built-in pip.
First of all, check that pyenv is installed correctly. The executables of python and pip should point to the pyenv shims:
$ type python
python is /home/tyrion/.local/share/pyenv/shims/python
$ type pip
pip is /home/tyrion/.local/share/pyenv/shims/pip
Then, the usual workflow with pyenv is the following:
List the python versions installed on your system
$ pyenv versions
* system (set by /home/tyrion/.local/share/pyenv/version)
3.6.8
3.8.1
other_version
Activate the Python version that you want to use, with pyenv shell, pyenv local or pyenv global:
$ pyenv shell 3.8.1
Check that the Python and Pip executable are what we expect (same version of python):
$ pyenv which python
/home/tyrion/.local/share/pyenv/versions/3.8.1/bin/python
$ pyenv which pip
/home/tyrion/.local/share/pyenv/versions/3.8.1/bin/pip
Install your dependency
pip install numpy
Note that if you installed pyenv in your home folder, you do not need to use sudo!
Use your library
$ python
>>> import numpy

Running bpython inside a virtualenv

I have created a virtualenv and installed SQLAlchemy in it:
$ virtualenv alchemy
$ source alchemy/bin/activate
$ pip install sqlalchemy
import works in python:
$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7
But it does not work in bpython:
>>> import sqlalchemy
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: No module named sqlalchemy
Why can't bpython find the package installed in the virtualenv, even though it is executed after source alchemy/bin/activate is called?
bpython must be installed in the virtualenv, otherwise the external, system-wide bpython is called:
$ source alchemy/bin/activate
(alchemy)[ 10:34PM ] [ adamatan#rubidium:/tmp ]
$ pip install bpython
...
$ alchemy/bin/bpython
--------------
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7
bpython has the python it was installed with hardcoded in its shebang.
You can manually edit it to make it use the current python. Open the script by running for instance $ vi $(which bpython).
Then change the top line from eg. #!/usr/bin/python3 to eg. #!/usr/bin/env python3.
That should make it run using the venv's python. It's not supported officially by bpython but it has always worked for me on both Mac OS X and Ubuntu.
Run bpython as module works for me
mkdir workout && cd workout
venv shell --python=3.8
Install your dependencies, e.g., pipenv install gcloud
pipenv install bpython
python -m bpython
python -m bpython
bpython version 0.21 on top of Python 3.8.5 /home/dennys/.local/share/virtualenvs/workout-qTtsVfjR/bin/python
>>> from gcloud import bigquery
>>>
Bpython must be installed with pip3 inside each virtualenv
$ virtualenv .
$ source bin/activate
$ pip3 install bpython
$ pip3 install sqlalchemy
$ bpython
>>> import slqalchemy

Installation of nltk-3.0a3 for python3.3.3 - "ImportError: No module named 'setuptools'"

I have installed Python 3.3.3 with a command:
sudo apt-get install python3
I am calling it as Python3, because I have Python 2.7 installed as well.
I have also installed distribute (setuptools) with a command:
sudo apt-get install python3-setuptools
To be sure, setuptools are installed for python3, I have searched with pip3 and I received an output:
$ pip3 search setuptools
setuptools - Easily download, build, install, upgrade, and
uninstall Python packages
INSTALLED: 2.0 (latest)
Now I want to install NLTK's version for Python 3, so nltk3.0a3. I have downloaded it from the official site, and in the folder I ran a standard python installation and received an output:
$ python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 33, in <module>
from setuptools import setup, find_packages
ImportError: No module named 'setuptools'
And in fact, when I go to python3 command line, for that input, I see the output:
>>> help('modules setup')
ez_setup - Bootstrap setuptools installation
setup
unittest.test.test_setups
So there is really no module called setuptools...
Does anyone know what am I doing wrong? Or is there any other way of installing NLTK for python 3? (in apt, there is only NLTK for python 2).
Thanks a lot guys for any effort!
You can use muon or your favorite package manager to install python3-setuptools and an experimental version of nltk supporting Python 3 is available at http://nltk.org/nltk3-alpha/
I suspect you will also need pyyaml and numpy installed for your python 3.
I gave this a try:
muon
check that I have installed python3-setuptools and python3-numpy
sudo pip3 install pyyaml
Having downloaded and unpacked the code from the above link
cd ~/ToolBuild/nltk-3.0a3/nltk-3.0a3
sudo python3 setup.py install
python3
Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> dir(nltk)
['AbstractLazySequence', 'AffixTagger', 'AlignedSent', 'Alignment', 'AnnotationTask', 'Assignment', 'BigramAssocMeasures', 'BigramCollocationFinder', 'BigramTagger', 'BinaryMaxentFeatureEncoding', 'BlanklineTokenizer', 'BottomUpChartParser', 'BottomUpLeftCornerChartParser', 'BottomUpProbabilisticChartParser', 'Boxer', 'BrillTagger', 'BrillTaggerTrainer', 'CfgReadingCommand', 'ChartParser', 'ChunkParserI',..........

Categories

Resources