Getting a very strange error. I am making a virtual environment and initializing it with a pip requirements.txt file, but when I go to run code in the activated environment, the virtual environment interpreter claims to be missing some (and only some) of the modules:
(venv) $ pip list
certifi (2017.7.27.1)
chardet (3.0.4)
decorator (4.1.2)
idna (2.5)
ipython (6.1.0)
ipython-genutils (0.2.0)
jedi (0.10.2)
numpy (1.13.1)
olefile (0.44)
pexpect (4.2.1)
pickleshare (0.7.4)
Pillow (4.2.1)
pip (9.0.1)
prompt-toolkit (1.0.15)
protobuf (3.3.0)
ptyprocess (0.5.2)
Pygments (2.2.0)
PyYAML (3.12)
pyzmq (16.0.2)
requests (2.18.3)
scipy (0.19.1)
setuptools (38.5.1)
simplegeneric (0.8.1)
six (1.10.0)
torch (0.2.0.post3)
torchvision (0.2.0)
tornado (4.5.1)
tqdm (4.15.0)
traitlets (4.3.2)
urllib3 (1.22)
visdom (0.1.5)
wcwidth (0.1.7)
wheel (0.30.0)
So I double check:
(venv) $ pip install tqdm
Requirement already satisfied: tqdm in ./venv/lib/python3.6/site-packages
(venv) $ python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tqdm import tqdm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tqdm'
people have suggested forcing a reinstall, using a different interpreter source, and just reinstalling. None of these have worked. this is very mysterious. Have any of you seen anything like this? Saw a similar unresolved problem here
UPDATE: Fixed. H/T to #Riverman for helping my find the issue: the problem was that an old unused alias was left over from a while ago, and while pip still had it own point back to python3.6, the python command itself was aliased to some old Anaconda3 version I had lying around somewhere. Alias, I forgot, do not go away by just re-sourcing your .bashrc file, so I ran unalias with the offending python command and it worked!
Would still love to hear from people though if they could explain why this can occur, though. I though venv completely insulated you from the outside environment...is it because aliasing is a system level effect so it seeps into the venv??
While being inside the virtualenv, please issue the following commands:
pip freeze
pip -V
python -V
which python
which pip
Share your results here to analyze it. I've also experienced pretty similar issues with the requests package before, but that happened on windows to me.
You used pip(which installs for Python 2.7) and you are trying to import the installed package in Python3 so it wont work.
You should do pip3 install package-name .
pip3 installs for Python3. Install pip3 using apt-get install python3-pip
It will work.
I had a very similar problem: I was working on a virtual environment (virtualenv) and installed pandas inside this environment with:
pip3 install pandas
However, when I tried to import this module when working on a jupyter notebook that was also inside this virtual environment with the command:
import pandas as pd
I was getting the error:
ModuleNotFoundError: No module named 'pandas'
Finally, I noticed that, even though I was activating my jupyter notebook from inside my virtual environment, I was opening the jupyter notebook from outside my virtual environment (because I also had this module installed outside of all my virtual environments). My solution was to uninstall jupyter that was outside my virtual environments and when I ran again the juypter nb from inside the desired environment everything worked perfectly.
Related
I am attempting to use PySimpleGUI to create a very simple GUI, but when I run the command "python hello_world.py" I get the error:
File "hello_world.py", line 3, in <module>
import PySimpleGUI as sg
ImportError: No module named PySimpleGUI
I've run the command "pip install PySimpleGUI" and it says "Successfully installed PySimpleGUI-4.55.1." I'm not sure what I'm missing here.
Code snippet here:
# hello_world.py
import PySimpleGUI as sg
sg.Window(title="Hello World", layout=[[]], margins=(100,50)).read()
check where python is installed
import os
import sys
print(os.path.dirname(sys.executable))
>>C:\Program Files\Python310 #here 310 is python version your may be differrent
if this outputs inside C:\Program Files\Python310
check for C:\Program Files\Python310\Lib\site-packages\PySimpleGUI
if its not there then Run CMD as admin and try python -m pip install PySimpleGUI
Update pip to the current version via "python -m pip install --update pip".
It's strange, but my PySimpleGUI module became visible after I updated the pip from version 21.2.3 to version 22.0.4 via "python-m pip install --update pip".
Before the pip version update, the contents of my local environment looked like this:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 21.2.3
pycodestyle 2.8.0
pyflakes 2.4.0
setuptools 57.4.0
WARNING: You are using pip version 21.2.3; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\work\PycharmProjects\demo\env\Scripts\python.exe -m pip install --upgrade pip' command.
After the update:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 22.0.4
pycodestyle 2.8.0
pyflakes 2.4.0
PySimpleGUI 4.57.0
setuptools 57.4.0
And the program hello_world.py it began to run successfully.
EDIT Dec2021:
This seems to me like an bug with pip rather than PySimpleGUI. Try this https://pip.pypa.io/en/stable/installation/ reinstall pip in the python interpreter using this.
Original Answer:
You can check all the installed packages with
python3 -m pip list
And see if you find PySimpleGUI in it. If yes then python3 hello_world.py should work if not (i suspect latter) run
python3 -m pip install PySimpleGUI
Maybe do this import:
import PySimpleGUI
and then the version of PySimpleGUI instead of:
import PySimpleGUI
Doing this:
C:/Users/Test> pip list
in the terminal, for me, it says there's PySimpleGUI installed.
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
I use Jupyter Notebook with a virtual environment.
I have a dependency installed, but can't import it:
cell 1:
!pip3 install sent2vec
Requirement already satisfied: sent2vec in
venv/lib/python3.7/site-packages (0.0.0)
cell 2:
import sent2vec
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-06231d291a17> in <module>
----> 1 import sent2vec
ModuleNotFoundError: No module named 'sent2vec'
How this can happen? How to fix this?
> pip3 list
Package Version
------------ ---------
certifi 2019.9.11
chardet 3.0.4
Cython 0.29.14
idna 2.8
joblib 0.14.0
langdetect 1.0.7
nltk 3.4.4
numpy 1.17.1
pip 19.3.1
requests 2.22.0
scikit-learn 0.21.3
scipy 1.3.2
sent2vec 0.0.0
setuptools 41.6.0
six 1.13.0
urllib3 1.25.7
wheel 0.33.6
You'll note that jupyter is not listed in your installed packages. That means you're running it from a different virtual environment. As I mentioned in the comment responding to your question, you can run which jupyter to find out where your Jupyter Notebook application is being run from (assuming you're on a *NIX system); in this case, it won't be from the python3.7 virtual environment that shows up in your first code block.
To resolve the issue, you simply need to run pip3 install jupyter, then retry running jupyter notebook.
Alternatively, you can add your virtual environment as a kernel so that it can be selected when you're running Jupyter from your original environment. To do this, you would run (assuming pip is connected to your original environment):
pip install ipykernel
ipython kernel install --user --name=<insert name of your venv>
You should then be able to select that venv as a kernel on new notebooks. (Source for info on venv activation in Jupyter).
Try by installing directly within Jupyter using the following command:
import sys
!{sys.executable} -m pip install your_package_name
Run this (with envname your enviroment name):
jupyter kernelspec uninstall envname
ipython kernel install --user --name=envname
Sometimes Jupyter doesnt update properly the kernels associated with enviroments.
So the solution is to uninstall it and install it again.
I had the same problem and this fixed it
It apears that you need Numpy 1.17.1(you have Numpy 1.16.0) to use sent2vec
requirements https://github.com/epfml/sent2vec/blob/master/requirements.txt
I have just reinstalled latest tensorflow on ubuntu:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
[sudo] password for ubuntu:
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl (13.8MB)
100% |████████████████████████████████| 13.8MB 32kB/s
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: protobuf==3.0.0b2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: tensorflow
Found existing installation: tensorflow 0.7.1
Uninstalling tensorflow-0.7.1:
Successfully uninstalled tensorflow-0.7.1
Successfully installed tensorflow-0.7.1
When following the directions to test it fails with cannot import name pywrap_tensorflow:
$ ipython
/git/tensorflow/tensorflow/__init__.py in <module>()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
/git/tensorflow/tensorflow/python/__init__.py in <module>()
43 _default_dlopen_flags = sys.getdlopenflags()
44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
46 sys.setdlopenflags(_default_dlopen_flags)
47
ImportError: cannot import name pywrap_tensorflow
Is there an additional change needed to my python or ubuntu/bash environment?
From the path in your stack trace (/git/tensorflow/tensorflow/…), it looks like your Python path may be loading the tensorflow libraries from the source directory, rather than the version that you have installed. As a result, it is unable to find the (compiled) pywrap_tensorflow library, which is installed in a different directory.
A common solution is to cd out of the /git/tensorflow directory before starting python or ipython.
The command below helped me.
pip install tensorflow --upgrade --force-reinstall
I compiled, installed TensorFlow from source (GitHub: https://github.com/tensorflow/tensorflow) in a Python 2.7 virtual environment (venv). It worked fine, but I needed (as others have mentioned, e.g. user "mrry" at Error running basic tensorflow example) to cd out of the partition in which I had compiled TensorFlow, to another partition, in order to be able to import tensorflow into Python. Otherwise, I got various errors, depending on which (source partition) directory I was in. To clarify:
source: /mnt/Vancouver/apps/tensorflow
can't import tf: Python launched in any of /mnt/...
can import tf: Python launched in /home/victoria/...
I later just followed the instructions here,
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
and everything just works, fine.
For reference, I am operating on
Arch Linux [4.6.3-1-ARCH] x86_64
Intel i7-4790
xfce 4.12 desktop environment
INSTALL STEPS:
Modify paths, venv names as per your preferences.
Create tf-env:
cd /home/victoria/anaconda3/envs
conda create -n tf-env python=2.7 anaconda
Note: appending the 'anaconda' metapackage installs ALL Anaconda packages (NumPy; ...).
Source activate that venv (tf-env)
source activate tf-env
Note: added to ~/.bashrc as an alias:
alias tf='echo " [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env'
Install TensorFlow in the tf-env venv:
(tf-env)$ conda install -c conda-forge tensorflow
THIS obviates the use of pip (including the *.whl install script), an alternative approach to installing TensorFlow that is described here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md).
WORKS!
(tf-env)[victoria#victoria ~]$ P
[P: python]
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow
>>> print tensorflow.__version__
0.9.0
>>> [Ctrl-D]
(tf-env)[victoria#victoria ~]$
You may then work with TensorFlow in the tf-env; e.g., in Jupyter notebooks launched in this (tf-env) venv.
Tensorflow 2.0 Compatible Answer: Both mrry's solution and neustart47's work for Tensorflow Version >= 2.0.
Answer 1: cd out of the /git/tensorflow directory before starting python or ipython.
Answer 2: pip install tensorflow --upgrade --force-reinstall or
!pip install tensorflow==2.0 --force-reinstall
In my python -m venv environment it appeared to be fixed by:
pip uninstall tensorflow
Change requirements.txt to say tensorflow==1.5.0 instead of tensorflow==1.8.0.
pip install -r requirements.txt
if you using CPU manufactured before 2011 then downgraded the tensorflow version from 1.8.0 to 1.5.0 or 1.2.0 and try to import the module it worked for me.
Installing via the following command solves the problem:
pip install --upgrade
Here's the link to download
I figured out that TensorFlow 1.12.0 only works with Python version 3.5.2. I had Python 3.7 but that didn't work. So, I had to downgrade Python and then I could install TensorFlow it works.
To downgrade your python version from 3.7 to 3.6
conda install python=3.6.8
I'm using tensorflow 1.13.1. Just reinstalling tensorflow worked for me.
I also have this issue and have been looking into it for a long time. It seems that there is no such problem on python 3+. On py2.7- The problem is actually on google.protobuf
Solution 1:
pip uninstall protobuf
pip uninstall google
pip install google
pip install protobuf
pip install google-cloud
Solution 2:
create an __init__.py in "google" folder.
cd /path/to/your/env/lib/python2.7/site-packages/google
touch __init__.py
Hopefully it will work.
I resolve the problem.
Try the follow command:
pip install --upgrade pip
trying to install Biopython on Fedora 21, Python 2.7. I've done the following
[mike#localhost Downloads](17:32)$ sudo pip2.7 install biopython
You are using pip version 6.1.1, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting biopython
/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading biopython-1.65.tar.gz (12.6MB)
100% |████████████████████████████████| 12.6MB 33kB/s
Installing collected packages: biopython
Running setup.py install for biopython
Successfully installed biopython-1.65
And then
[mike#localhost Downloads](17:32)$ ipython
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
In [1]: import Bio
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a7440e1156be> in <module>()
----> 1 import Bio
ImportError: No module named Bio
What am I doing wrong?
EDIT
I tried installing biopython using
sudo easy_install -f http://biopython.org/DIST/ biopython
and it installed it into /usr/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg/. Didn't work.
Then I tried installing it using the same command, without the sudo:
easy_install -f http://biopython.org/DIST/ biopython
which installed it into /home/mike/anaconda/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg
And that worked! Both for ipython and python. But why did it work...?
One should be very careful when using pip and the like that it is the pip which goes along with the supposed Python interpreter.
I see that you are trying to import Bio from the Python interpreter you get by typing ipython. You can make sure that you invoke the pip of exactly this interpreter like so:
sudo ipython -m pip install biopython
Note that the installation is not exclusive to ipython. It is however exclusive to whatever Python installation ipython is installed on top of.
It's not good practice to sudo pip, since it may install things under root permission, which is usually not granted to ordinary program.
The problem probably lies in library path. The most informative tools will be
import sys
print (sys.path)
and
which python
pip --version
And use pip install biopython --user to replace sudo pip