The simple import of requests
import requests
can be executes and used in windows shell but the same code says in pycharm:
Traceback (most recent call last):
File "C:/Users/XPS13/PycharmProjects/Testing/Webcrawler_Test.py", line 1, in
<module>
import requests
ModuleNotFoundError: No module named 'requests'
requests was correctly pip installed. Even uninstalling and reinstalling doesn't work.
Any help would be appreciated.
Yeah so this might be a little late but I fixed my problem like this:
Go to Settings/Preferences
Select Project Interpreter
And press the + button on the left side
That + sign
Search for requests
And press Install Package
I am running:
Windows 10
Python 3.7.1
You need to configure the project interpreter in PyCharm:
Go to Settings/Preferences
Select Project Interpreter
Click the little gear and click Add...
Select the appropriate interpreter (whether a virtual environment or system python installation)
Settings top right
'+' above Package table
Search: Requests & highlight in list
Install Package
Related
I am really frustrated right now and have tried so many workarounds all to no avail. I want to do some analysis on a csv file and I learnt that I would need to import pandas.
So I installed python version 3.10.5 and ran this code in terminal:
pip3 install pandas
This successfully installed pandas on terminal in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages
I ran this code on my Atom IDE and VScode too:
import pandas as pd
This was the error:
[Running] python -u "/Users/augustine/Downloads/pythonscripts/tempCodeRunnerFile.python" Traceback (most recent call last): File "/Users/augustine/Downloads/pythonscripts/tempCodeRunnerFile.python", line 1, in <module>
import pandas as pd
ImportError: No module named pandas
I saw on reddit that only python 3.9 supports pandas for now. I uninstalled version 3.10 and installed 3.9, on VS code, I changed the python interpreter to 3.9 version but it's the same thing happening. Please what am I supposed to do?
It's good practice that every time you make a new project involving python, to change to that project's base directory and then run python -m venv venv to set up a stable python environment there, when you use it you run ./venv/Scripts/activate, and then all dependencies can be managed in a requirements.txt file. The added bonus is if u do that, vscode will see it and then auto-suggest whether you want that to be the default interpreter for your project code. If that doesnt happen, try the magic "ctrl + shift + p" and then start typing "python interpreter" -- an option will appear for you "Python: select interpreter" and then just use the one you've created in the venv (./venv/Scripts/python.exe).
I think this is related to the existence of multiple Python in your environment. Try to manually specify the python location in setting.json:
"python.defaultInterpreterPath": "C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",#your python path
I want to use the tkinter module and PyCharm is making it difficult. I am using the Python 3.7 Interpreter, and I have not been able to use it.
I have tried a few things:
pip install tkinter
pip3 install tkinter
sudo apt install tkinter
sudo apt install python-tk
None of these have success
Whenever I use import tkinter, it just returns the error
Traceback (most recent call last):
File "/home/removed/PycharmProjects/Tutorials/GUI.py", line 1, in <module>
import tkinter
ModuleNotFoundError: No module named 'tkinter'
Process finished with exit code 1
Anyone know of a solution?
Always make sure you have the right interpreter selected;
In PyCharm, you can check this by pressing ctrl + alt + s, and navigating to the "project interpreter" tab. Here you can select the different python installations on your system.
This thread might be a little old but I had the same problem for the past 3 days. My solution was as follows (btw I'm running Linux Mint 19 Cinnamon with python3.x):
-Remove PyCharm (I had installed it via Linux Mint's software center)
-Download PyCharm from the JetBrains website.
the "tkinter" module was by installed and recognized by default.
I am trying to import the thing in python that will enable me to copy and past things. It seems to have a problem. I later searched my entire C drive for pyperclip and it seems to be not have it at all. How can I go about fixing this? Or am I not looking in the right area? Here is the error:
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
BTW I'm on windows 10
You seems a new learner for Python. You can try to install that package via pip command. For other problem like how to use pip or which user to run pip, just go to search and solve it by yourself.
So yes you're right. You need to open up cmd prompt. use the cd to change the directory to the one inside Python36\Scripts. Then run the command
pip install pyperclip
I am new to python in pydev (eclipse).
I am trying to import requests and get an error:
import requests
error:
unresolved import: requests
In terminal I tried:
pip install requests
and it says
Requirement already satisfied
Also there is no error or warning when running brew doctor. What am I missing?
The issue was that the Python pointed by pydev was different from the default python in the terminal that installed requests module.
The fix was to go to preferences -> pydev -> pydev interpreter -> click on the python (wrong python path) and remove, and then click on new to add the right python installed by brew. To find the python path installed by brew type which python in the terminal).
First type python in the terminal -> Now you have the version of python.
Second Step: If you use Vscode in windows or mac, click on the gear button on the bottom left of the screen which is settings of Vscode, select extensions in it, choose python from the list menu on left side, press command+shift+P or ctrl+shift+P and type "Select Interpreter", now select the version you have got in the first step. And you are good to go.
I installed bottle on Python 3.4 with pip install. In the terminal, when I do:
$ python3.4
>>>import bottle # shows no import error
>>>
but when I do it in PyCharm, it says:
import bottle ImportError: No module named 'bottle'
in your PyCharm project:
press Ctrl+Alt+s to open the settings
on the left column, select Project Interpreter
on the top right there is a list of python binaries found on your system, pick the right one
eventually click the + button to install additional python modules
validate
In some cases no "No module ..." can appear even on local files. In such cases you just need to mark appropriate directories as "source directories":
The settings are changed for PyCharm 5+.
Go to File > Default Settings
In left sidebar, click Default Project > Project Interpreter
At bottom of window, click + to install or - to uninstall.
If we click +, a new window opens where we can decrease the results by entering the package name/keyword.
Install the package.
Go to File > Invalidate caches/restart and click Invalidate and Restart to apply changes and restart PyCharm.
Settings:
Install package:
I am using Ubuntu 16.04. For me, it was the incorrect interpreter, which was by default using the virtual interpreter from the project.
So, make sure you select the correct one, as the pip install will install the package to the system Python interpreter.
PyCharm 2019.3, my solution is below:
For me, none of the above worked, and curiously even within one file some imports worked, some didn't:
from folder1.folder2.folder3.my_python_file import this_function # worked
from folder1.folder2.folder3.my_python_file import that_function # didn't work
Follow the above advice, but if it doesn't fix it additionally, (in PyCharm) click File >> Repair IDE and confirm all the 6 steps one after another.
I had virtual env site package problem and this solved it:
In the case where you are able to import the module when using the CLI interpreter but not in PyCharm, make sure your project interpreter in PyCharm is set to an actual interpreter (eg. /usr/bin/python2.7) and not venv (~/PycharmProject/venv/...)
I had the same problem, I tried all fixes like installing from the project interpreter and installing from python console, nothing worked. What worked was just going to the project folder from the terminal and installing it from there.