I installed psycopg2 via pip, but my programs are having trouble finding it.
So, I tried to install psycopg2 via pip again:
user#ubuntu:~/Desktop/progFolder$ sudo pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Then I tried to use a program that imports it:
user#ubuntu:~/Desktop/progFolder$ python myProg.py
Traceback (most recent call last):
File "myProg.py", line 6, in <module>
import psycopg2
ImportError: No module named psycopg2
And I have tried just importing directly in python:
user#ubuntu:~/Desktop/progFolder$ python
Python 2.7.5 (default, Nov 9 2014, 14:14:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
So I printed my python path.
>>> import sys
>>> print sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
And noticed that the path does contain the path to psycopg2.
psycopg2 in /usr/local/lib/python2.7/dist-packages
So, I have no idea on why this is happening. Any help would be appreciated.
UPDATE:
I have done
>>>help()
>>>modules
And psycopg2 was not listed among the other modules. (this does not help me but may help you help me)
Your pip looks ok (that is, it's the system/default one). Your Python executable, however, is something that didn't come by default with 14.04 LTS (e.g., on my 14.04 system, it's /usr/bin/python). Did you install that Python yourself? Then you need to install (and use) the corresponding pip as well. (Normally, Python would have come with a pip installation, but apparently in this case, it didn't.)
pip can be fairly simple installed from its installation instructions.
Though first, verify that
you did install /usr/local/bin/python yourself. That is, it didn't come with some other piece of software that you installed and that, along the way, decided to install Python there.
you want to use /usr/local/bin/python (I guess it is a more recent version of Python 2.7; the default 14.04 LTS one appears to be 2.6.7 as of 2015-08-03).
From your python path print, it looks like it doesn't have /usr/local/lib/python2.7/dist-packages included in it. You can add it in one way by:
sys.path.insert(0, "/usr/local/lib/python2.7/dist-packages")
Related
My OS: win 10 ,
installed:
python 2.7 ( command is python)
python 3.9.5 ( command is python3)
pip , pip3 ( both for python3, seems )
pip command:
c:\>pip3 config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'
c:\>pip config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'
I installed xlwt via pip, and I can see it's installed :
c:\>pip install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)
However, when I try to import it, got error: No module named xlwt
c:\>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlwt
>>> exit()
Also, I used pip3 install xlwt successfully, but run python3 ... import xlwt failed. full log:
C:\files\dong_tai_pai_fang_ji_suan\python_code>pip3 install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)
C:\files\dong_tai_pai_fang_ji_suan\python_code>python3
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlwt'
>>>
how to resolve this?
should I configure the windows PATH or something for python/pip ?
thanks
edit:
maybe I installed multiple python3:
your python version is 2.7 in python console.
change to python 3.9 version.
maybe I installed multiple python3
Do python3 -m pip install xlwt, this always install for python3 (python launched when you do python3 in terminal), then it should be possible to import installed module in python3. If you want to know more about that read Installing Python Modules in docs.
OK at last I find the root cause.
There are 2 versions of python in my PC:
version 3.9, this is installed by myself.
version 2.7, this is automatically installed by electron-vue
and I believe there are some conflicts between these two version's configuration. ( e.g. execute path, pip path, etc ) which makes pip install work incorrectly.
solution is quite simple: uninstall all the python version and re-install 3.7, everything goes well!
Note - I already check numpy import error related threads but none helped
I am using debian 8 where default python is 2.7.9. I installed python 3.4.2 and created virutal env.
Within virtual environment -
python -V
Python 3.4.2
pip -V
pip 1.5.6 from /path/venv34/lib/python3.4/site-packages (python 3.4)
I have python3 numpy package - python3-numpy_1.12.0-2~pn0_amd64.deb
which I have installed with sudo dpkg -i python3-numpy_1.12.0-2~pn0_amd64.deb
which successfully completed.
Now when I do
python
Python 3.4.2 (default, Feb 7 2019, 06:08:06)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'
>>>
Any clue what's wrong here?
python3.4 -m pip install numpy==1.12.0-2
ok since my repo is less than 50 i can not add comments, so take this answer as a comment to your question.
I think numpy is installed but not in your virtualenv, make sure your virtualenv is active when you are trying to install any library, you will see virtualenv name in every command line if it is activated.
(venv) C:\Users\seventeen\sprint25>
Try python -m pip install numpy==1.12.0. This should help you.
After installing xlrd using pip, I am still unable to get it to work in my script. I'm not sure if I am missing something completely obvious - please help!
Currently, entering pip list on command line gives the following:
pip (9.0.1)
setuptools (32.1.0)
wheel (0.29.0)
xlrd (1.0.0)
And entering pip show xlrd gives:
Name: xlrd
Version: 1.0.0
Summary: Library for developers to extract data from Microsoft Excel (tm) spreadsheet files
Home-page: http://www.python-excel.org/
Author: John Machin
Author-email: sjmachin#lexicon.net
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires:
Yet, if I go into the python environment (via typing python on command line) and try to import, here's what I get:
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlrd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlrd
Anyone has encountered this problem before? I also have python 3 installed, and I downloaded xlrd via pip3. Yet import xlrd doesn't work on either versions (2 or 3).
you can try this:
import pip
package_name='xlrd'
pip.main(['install', package_name])
First, you can check if such package actually exists on given directory (simply ls /usr/local/lib/python2.7/site-packages to see if there is __init__.py there).
If package is on place, you may check environmental variable $PYTHONPATH or just python -c 'import sys; print(sys.path)', which prints all directories where Python takes libraries from.
If everything is in place and sys.path contains site-packages (if that's not your first package installed via PIP I assume that everything's correct there), it might be problem with permissions. Please check some other stackoverflow question:
Cannot import a python module that is definitely installed (mechanize)
If package was installed with root's rw permission only - that would be the case.
Uninstall and install xlrd. May be at installing time you would have got some error. This error shows only if xlrd is not installed.
Use sudo pip install xlrd to install in python 2.7
I solved the issue with upgrading pip and following Bibek Ghimire's answer. It seems that I was using pip version 9 whereas version 18 has been already realized.
pip list
pip install xlrd
pip install xlrd == 1.2.0
now go to your IDE and start typing
import xlrd
its done now!
I'm still super new to coding! Trying to learn from online tutorials, but I seem to be stuck on the first step! I think I installed bs4, but it's not showing up in python3, is it installed in the wrong place?
robbie$ sudo -H pip install bs4
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /Library/Python/2.7/site-packages (from bs4)
Robbies-MBP:~ robbie$ python3
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
Any help would be greatly appreciated :)
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
You have the module installed for Python 2.7, however you're using and trying to import it with Python 3.6.
You have to use pip3 like you use python3.
If you are using python 3 then you shoud use pip 3. In order to install it in ubuntu:
sudo apt install python3-pip
And then use the following command for installing the module bs4:
pip3 install bs4
go to the bottom left of your vs code and select python 3.9.1 64 bit (depending on the version of your python). it'll work.
it works for me
Just a quick note but a lot of times when this happens and you are running python3 and you used pip3 to install bs4 or another module but are running two different versions of python3 (eg 3.4 and 3.6). Sometimes just doing a normal update in a distro like CentOS installs a newer version of python, but not the corresponding pip.
Take for example here where a user is running python3.6 but all modules are installed only for python3.4 and there is no pip3.6 available.
http://realtechtalk.com/python_ModuleNotFoundError_No_module_named_bs4_even_though_you_have_the_module-2267-articles
I was having the same issue but managed to solve it with custom install script in the code. This tries to import and if it fails, automatically installs it
def safe_import(module):
try:
exec(f'import {module}')
globals()[module] = eval(module)
except ModuleNotFoundError as err:
import os
os.system(f'pip install {module}')
exec(f'import {module}')
globals()[module] = eval(module)
I would like to install a module but pip is not installing it in the right directory which I assume should be /usr/local/lib/python2.7/site-packages/. After all, I just installed Python 2.7.2 today. Originally I had 2.6.5 and had installed modules successfully there. So I think something is wrong with my Python path.
How to have all my module installations go to the proper python2.7 directory?
s3z#s3z-laptop:~$ pip install requests
Requirement already satisfied: requests in /usr/local/lib/python2.6/dist-packages/requests-0.6.1-py2.6.egg
Installing collected packages: requests
Successfully installed requests
s3z#s3z-laptop:~$ python
Python 2.7.2 (default, Oct 1 2011, 14:26:08)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>> ^Z
[3]+ Stopped python
Also here is what my Python directories look like now http://pastie.org/2623543
After you installed Python 2.7, did you install the Python 2.7 version of easy_install and PIP? The existing installations are configured to use Python 2.6 by default which may be causing your issue.
You are probably using pip linked to python2.6, instead of 2.7. If you have installed pip properly with python2.7, you can do:
pip-2.7 install requests
If not, try installing this way:
curl -O http://python-distribute.org/distribute_setup.py
[sudo] python2.7 distribute_setup.py
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
[sudo] python2.7 get-pip.py