I am working with python flask's requests module. I have installed requests module using :
pip install requests
And verified that requests module exists when I run :
pip list
But when I run my python application , I receive import Error for requests module.
I noticed that pip is installing the module in C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\ folder BUT the interpreter is looking for the module in C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\ folder.
I have tried running the command :
pip install --install-option="Path to install in" requests
But threw some other error.
The import error I am getting states :
ImportError: cannot import name 'requests' from 'flask'
(C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\__init__.py)
I am working in virtualenv in Windows 10.
I recently had the same problem installing a self made package. I installed it with pip install <package> and checked it was actually installed with pip list but running the script with import <package> returned a ModuleNotFoundError: No module named <package>.
I solved the problem creating an empty file called __init__.py in the package directory.
Check https://pythontips.com/2013/07/28/what-is-init-py/ and https://docs.python.org/3/tutorial/modules.html#packages for better understanding.
what if you add that folder to your path? using sys.path.extend?
I solved it using python3 -m pip install <package name>. In the OP's case, it should be python3 -m pip install requests.
Note that I'm using python 3.10.
Relatively new to Python I've created a project using Pipenv that uses the xmltodict module. I've looked at some similar questions but can't find exactly what I need to do.
I've used pipenv to install the xmltodict module but I'm still getting the following error:
Traceback (most recent call last):
File "./storagereport.py", line 12, in <module>
import xmltodict
ImportError: No module named 'xmltodict'
Pipenv shows that the module is installed:
$ pipenv graph
xmltodict==0.12.0
Can anyone help?
You might be running Python from another version , which is usually the default version that is installed. If that's the case, in your virtual environment you will find python.exe and pip.exe you have to run pip from the virtual environment
Try with following command:
sudo pip install xmltodict
or
sudo pip install xmltodict --upgrade
I run into this regularly, I believe because I'm behind a firewall. I download the package that I need to my computer and then I install it. If that doesn't work, I navigate to the download folder where it is and install it from there. You can download this package here:
https://pypi.org/project/xmltodict/
I downloaded the file from here- https://pypi.org/project/xmltodict/#files and after extraction placed the .py file in the directory where I was importing xmltodict. Then it worked fine.
I'm trying to install: https://github.com/rozzac90/pinnacle.git from source.
If I type sudo python setup.py install (or sudo python setup.py configure) I get:
import requests
ImportError: No module named requests
The module is installed, I'm sure. It is in the list of conda installed packs. Also, if I try to import it in other scripts, and
python
>>> import requests
>>>
with both python 2 and python3. I get no errors.
I also removed it and installed it again. Same results.
I am using Anaconda with a python3 environment. (I get the same errors in python 2, though.) So I can't use pip commands. I'm running a lubuntu machine, latest version.
Ideas anyone? Thanks in advance !
A suggested answer :
The solution was to run the script in the folder where setup.py is located, in general :
Try with
sudo /[annaconda_python_path]/python setup.py install
Make sure the right environment is active in the terminal.
I am new to installing new python modules.
I installed tweepy using pip install tweepy. The installation was successful and 2 folders tweepy & tweepy-3.3.0.dist-info are created in the Lib/site-packages, hence I assumed all should be fine.
However, when I went to the IDE and import tweepy. It is unable to detect the module:
>>> import tweepy
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named tweepy
What is wrong?
I am running python 2.7.5.
[Update 1] I am using windows 7.
I first installed pip using another forum's suggestion (How do I install pip on Windows?). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation.
[Update 2] Using a file with import tweepy and running it, I have a similar error.
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\xxxx\Desktop\Script1.py", line 2, in <module>
from tweepy import Stream
ImportError: No module named tweepy
[Update 3] Typed "pip freeze" in cmd. It does show tweepy=3.3.0
C:\Python27\Scripts>pip freeze
oauthlib==0.7.2
requests==2.7.0
requests-oauthlib==0.5.0
six==1.9.0
tweepy==3.3.0
wheel==0.24.0
[Answer] Thanks for all the help guys, especially Cleb & omri_saadon suggestion that there might be something wrong with the file path.
I just realised that my GIS software, ArcGIS by default installed another Python into the Python27 folder, and everything is taken from that folder, C:\Python27\ArcGIS10.2, instead of C:\Python27. After I install tweepy from C:\Python27\ArcGIS10.2\Scripts, everything works well.
Try to pip uninstall tweepy
and then again pip install tweepy
Make sure you don't have several interpreters on your computer, if you have several, make sure that your pycharm(or any other editor you use) is configured with the same interpreter where you installed tweepy.
I tried this command py -m pip install tweepy and worked for me
If you are using Anaconda
conda install -c conda-forge tweepy
you may also use
easy_install tweepy
If you are using ubuntu try: sudo apt install python-pip
and then run: python3 -m pip install tweepy
I hope that helps!
If you are using conda enviroments and jupyter notebooks, you could try to install it from the notebook and restart the kernel:
!conda install -c conda-forge tweepy
The problem is that , tweepy in getting installed in the native python environment, i.e you might be able to import it in cmdline but must be getting error in jupyter notebook.
If this is the case, then you might need to install it with conda environment , with conda install tweepy. But if in this case also if you fail to install it due to conflicts errors thrown by conda do the following.....
Copy all the required tweepy pip files from the python environment, which you can find by running the pip install tweepy cmd which shows that the required package is already satisfied in a particular path.
You might be required to copy tweepy, requests, requests_oauthlib, oauthlib.
Paste the copied files into site-packages inside of Anaconda environment folder.
This solved the problem for me , hope it solves for you too.
If multiple versions of python are installed on the computer, you need to make sure under which version the package has been installed into. I have two versions of python installed on my mac, both python2 and python3 under /usr/local/lib path.
pipinstall tweepy only installs the package into python2.7/site-packages, while VSCode complies python3. Run pip3install tweepy to get the package under python3.7/site-packages so the module can be recognized by the compiler.
I had the same issue where after installing/ uninstalling via pip it still did not work. As a last ditch effort I actually moved the 'tweepy' folder in the '...Lib > site-packages' back to the main Python directory and 'import tweepy' then worked. No idea why this worked, but it did for me... Good luck!
I tried this, I was having the same error, but the thing that I did was, first installing the package using pip command, then spot the path where it got stored, then using os module change the directory to where the packages got stored, and then import it, it will work..
Very common error wherever your computer have different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown.
If you are using Jupyter Notebook, just run the command below in the cell of the notebook.
!pip install tweepy
If you are using Jupyter notebook on Anaconda try:
sudo conda install tweepy
This worked for me on OSX.
The same for me, typing direct in the console import tweepy it works, but when I tried to run from the script it says 'No module named 'tweepy'' i tried to uninstall and install again but the solution was more simple,
instead of run like
C:\script.py
I run
C:\python script.py
It works, Python version is 3.6.2 tweepy version is 3.5.0
If you are using Jupyter Notebook, the only thing that worked for me was to first install Jupyter again
pip install jupyter
and then install tweepy
pip install tweepy
I have Python 2.4 and 2.7 on my Centos server.
I would like to use PyCURL under Python 2.7.
I ran yum install pycurl and it appeared to install but when I attempt to import PyCURL it works fine for Python 2.4 but not for 2.7.
Can anyone advise how it is possible to install PyCURL (or any other Python extension for that matter as I can see this being an issue in future) to a specific version of python.
Thanks
C
------ SOULTION (thanks gjallar) ----------
Instead of using YUM I downloaded and installed PyCurl by running the setup.py file using the python version I wanted i.e.
sudo python2.7 setup.py install
This still didn't work as I was getting an error saying I had the wrong version of libcurl
To ressolve this I downloaded the latest curl version from http://curl.haxx.se/download.html and installed with the instructions here: http://curl.haxx.se/docs/install.html
Sadly, this still didn't work as when I tried to import pycurl in python I got:
File "<stdin>", line 1, in <module>
ImportError: libcurl.so.4: cannot open shared object file: No such file or directory
This was in turn ressolved by carrying out the command:
export LD_LIBRARY_PATH=/usr/local/lib
As suggested in the post:
Why can't Python find shared objects that are in directories in sys.path?
(Thanks Vinay)
Now it works.
One possible route you can take to install a certain application for a specific python version is to install pip using the specific python version and the use pip to install pyCURL.
In your case this should work by installing pip using python2.7 and then run pip install pycurl:
Install pip via distribute running the setup.py file with your python2.7 interpreter.
This requires pycurl to be available in PyPi - otherwise (if the pycurl download contains a setup.py) simple run the setup.py file using the interpreter you want to install it for.