I am getting ImportError : no module named 'requests'.
But I have installed the requests package using the command pip install requests.
On running the command pip freeze in the command prompt, the result is
requests==2.7.0
So why is this sort of error happening while running the python file?
Run in command prompt.
pip list
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
pip uninstall requests
Try after to install it:
pip install requests
You can also test if pip does not do the job.
easy_install requests
I had this error before when I was executing a python3 script, after this:
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
In Windows it worked for me only after trying the following:
1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item)
2. (Here is the path to your pip3.exe)\pip3.exe install requests
Done
if it works when you do :
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
in that case : check the location of your working python:
which python
And get sure it is matching the first line in your python code
#!<path_from_which_python_command>
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.
Related
I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.
I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.
So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.
But Still problem not fixed. Any idea how to fix this?
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python
interpreter it finds in the system path. To select a specific
environment, use the Python: Select Interpreter command from the
Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation:
https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2.
Pip3 is just for python3.
You must use pip2 or pip2.7 for work with python2.
Search if you got the pip2 package installed is not then install it.
I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.
I am attempting to use a small script to move my mouse slightly every minute or two to make the appearance that I am sitting at my desk (dont tell my boss please)
is anyone able to assist in why this might be happening?
from my command prompt I was able to successfully install pip install pyautogui
note, that: pip3 install autogui was not recognized
once I opened up pycharm, I ran the code, and got the below error:
ModuleNotFoundError: No module named 'pyautogui'
I also checked to make sure I had python 3 in command line using pip version = anaconda3\lib\site-packages\pip (python 3.7)
**full code below for reference
import pyautogui
import time
import sys
from datetime import datetime
pyautogui.FAILSAFE = False
numMin = None
if ((len(sys.argv)<2) or sys.argv[1].isalpha() or int(sys.argv[1])<1):
numMin = 1
else:
numMin = int(sys.argv[1])
while(True):
x=0
while(x<numMin):
time.sleep(60)
x+=1
for i in range(0,200):
pyautogui.moveTo(0,i*4)
pyautogui.moveTo(1,1)
for i in range(0,3):
pyautogui.press("shift")
print("Movement made at {}".format(datetime.now().time()))
https://github.com/Johnson468/Stay-Awake
for reference - i am using windows
You cannot import pyautogui from python 3 interpreter in pycharm because it is not installed.
When you ran pip install pyautogui you installed it on your python2.7 environment.
When you tried to installed it with pip3 you ran anaconda's pip (accordint to you error).
you can check which pip is used inside the CMD with the command where pip3.
If it is not found you can try running it like this: python -m pip but make sure you are running python3!
I highly recommend installing everything in venv virtual environment to make sure nothing is missing and you don't have any dependencies issues.
Or if you are new to python, uninstall all different instances and only keep one (probably python3 in your case), or edit you PATH in Windows
Furthermore I'm pretty sure when you are running pip from your console you are using another instance of it on your computer then the one you set as interpreter on pycharm, hence you couldn't use pip3 at all.
If none of the above helped, please add more details yo your question and I'll edit the answer.
Summary: You have a few instances of python installed on your computer (at least one of python2.7 and one of anaconda), when you run python or pip from the CMD if refers to the python2.7 one.
But when you chose an interpreter for you project in Pycharm you chose a python3 instance, which is obviously doesn't contain pyautogui.
Make sure you are using the right python instance when setting it up in Pycharm and when installing packages.
I answered this question recently: Problem with Python modules import on Mac
The issue might be that you don't have pip installed.
I know most Mac's have pip and Python pre-installed, but it wouldn't hurt to try: sudo easy_install pip
If this doesn't seem to be the issue, you might be running the pip install packageName in the wrong directory.
You will need to access your scripts folder in python and run the pip install packageName command in there. Here is a resource which should help you reach that directory: https://datatofish.com/install-package-python-using-pip/
This was answered for a Mac, but switching the commands to another OS shouldn't be hard. Just make sure pip is installed and that you're installing in the right directory.
I am having a nightmare tonight, I want to start learning some Django but I am running into quite a few problems while installing it.
I am following these tutorials - https://www.youtube.com/watch?v=UmljXZIypDc / https://www.youtube.com/watch?v=MEcWRk9w0t0
I installed Python 3.7.2 and confirmed the installation by typing 'python --version' into Terminal/Command Prompt.
I typed 'pip --version' into CMD and got this message in return "'pip' is not recognized as an internal or external command, operable program or batch file."
this is where I am stuck, I cannot continue any longer without completing this step, could anyone tell me where I am going wrong?
Thank you
edit: looks like it's a path issue, does anyone know how to do the following: how to I do this :
"Then add C:\Python37\Scripts path to your environment variable. Assumes that there is a Python37 folder in your C drive, that folder name may varied according to the installed python version Now you can install python packages by running pip install awesome_package_name"
You need to uninstall python and when you're installing python again , check on add python to PATH.It will remove the error
Can you be more specific as to which OS you are using? You can use pip also like python -m pip .... The -m part loads a python module It might just not be installed since it is a python module. On linux, for example you have to install pip separately (would be sudo apt-get install python-pip).
Run pip install django from windows command prompt instead of python shell.
Installing Django with pip
follow these to know more. https://docs.djangoproject.com/en/2.2/topics/install/
hope you will get it.
I tried doing the process I explained in the title, and even using the user-- method I cannot get it to install or find anything. I tried both later versions and the newer versions of the requests module in python.
Before this I tried without user and it had some error involving the fact that I had Python 2.7.
Thanks to all
just try
pip install --user requests
instead of Anthony type --user
--user makes pip install packages in your home directory instead, which doesn't require any special privileges.
https://stackoverflow.com/a/42989020/4414156
Bonus Tip: if you are using Atom, or for the sake of any editor and you are using PYTHON, you must use virtual environments. It will keep your packages clean and prevent conflict.
https://docs.python-guide.org/dev/virtualenvs/
https://atom.io/packages/atom-python-virtualenv