problem with importing pyinputplus module - python

I have a problem with importing module pyinputplus to my project.
I type 'pip install pyinputplus' in cmd (iam using windows), all was fine, cmd showed that installation was succes.
But when i try: import pyinputplus in my project in PyCharm i have an error: ModuleNotFoundError: No module named 'pyinputplus'
Some weeks ago i installed packed named selenium, and everything was fine. All works with no problem. I do the same with pyinputplus and its wrong...
Moreover, i tried to use pyinputplus in cmd and all was also fine. Where is a problem?

Pycharm creates virtual environments for each project, so installing it system-wide (as you just did) doesn't make it available to your pycharm project.
Easier Solution
The easy solution is to go to preferences, click "python interpreter" (you may need to expand "project"), then click the plus icon at the bottom of the package list, and search for pyinputplus and click install. It is now installed, but won't work for any other project.
Long-term Solution
Keeping packages seperate has it's advantages, like allowing you to have many different versions of packages, and avoid conflicts, but you may prefer for everything to use the same interpreter. If so, go to the same "python interpreter" page in preferences, and change the interpreter in the dropdown to the other available one. If there are more than 2, you may need to use trial and error.
Have a look at the documentation here: https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#interpreter-settings

Related

Can't solve "No module named 'numpy'" after hours of digging

I know this is a problem that's been asked here before, but I have tried all the solutions I found and not solved it. It's possible I'm not understanding the solutions, but I have tried my best.
I am teaching myself Python and it is slow going, so I don't understand a lot yet. I'm using VSCode as an IDE, Python version 3.10, and Windows 10. I only have the Python extension installed for VSCode. My project files are on a flash drive, D. I replaced a couple folder names with [Default Names] in the text below.
I keep trying to debug/run some code in VSCode and the very first line
import numpy as np
gives me the error
Exception has occurred: ModuleNotFoundError - No module named 'numpy'.
But I know that's not true:
`PS D:\0-Career\Programming\PythonCoding\[ProjectFolder]> py -m pip install numpy
Requirement already satisfied: numpy in c:\users\[UserID]\appdata\local\programs\python\python310\lib\site-packages (1.23.1)`
I tried the solution of going to
environment variables > system variables > "Path" > edit > new >
c:\users\[UserID]\appdata\local\programs\python\python310\
as well as
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Lib\site-packages\
and
C:\Users\[UserID]\AppData\Local\Programs\Python\Python310\Scripts\
and I also tried adding a user variable called Python. Nothing appears to have changed as a result of these additions.
Some history if it's helpful:
I first started by installing Python using the Microsoft Store. I used IDLE for a bit, and I used my command line to install pip and numpy. They worked for a little while. I later installed Visual Studio Code IDE. I ultimately have uninstalled the Microsoft Store version and installed the application from the Python site for Windows instead. I have also uninstalled and reinstalled it several times trying to fix my issues, and same for numpy. I also searched my C drive for "python" and burned everything from the past couple days and reinstalled and repaired it out of desperation. No luck.
I have tried to the best of my ability to uninstall everything and reinstall everything to start fresh, because numpy worked ever so briefly early on in IDLE, I think until I had installed the web download version of Python. I don't really understand environment variables, so I'm not sure what I'm doing or if I'm doing that wrong, or what needs to be restarted when I try something new, so it's possible I missed something.
Answers a 10 year old could understand would be appreciated! Or terminology I can easily research for an explanation of how to do it.
Ctrl+Shift+P open Command Palette
choose Python:Select Interpreter
Choose the right interpreter
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Also Check 64 bit or 32 bit
Download the latest version
and open the location where you downloaded the NumPy module now press the 'SHIFT' key and press right-click on the mouse then a menu will open where you find open PowerShell. open it now PowerShell window opens in the folder now type pip install and the file name and press the TAB button and click enter. then the NumPy module will be installed.
Have Fun
Try adding the variable PYTHONPATH to your system variables and add the following paths to this variable.
C:\PATH_TO_YOUR_PYTHON_INSTALL
C:\PATH_TO_YOUR_PYTHON_INSTALL\DLLs
C:\PATH_TO_YOUR_PYTHON_INSTALL\Lib
C:\PATH_TO_YOUR_PYTHON_INSTALL\Scripts
It should look something like this.
Screenshot of Environment Variables
After you added the variable restart your VS Code and it should work.
I hope this helps.

How do I import Pandas library into PyCharm?

I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error : ModuleNotFoundError: No module named 'pandas'
I have tried to uninstall and install again many times but nothing seems to work. Does anybody know a solution to this?
You can try downloading the library from PyCharm settings:
File -> Settings
then, Project: -> Python Interpreter
Click a + sign to the right,
Search for the pandas library,
and finally, press 'Install Package'
I think you have to choose the right python interpreter. Check my screenshot
You likely have multiple copies of Python installed on your system. PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.
There are two places where you specify a Python version. First of all, your Project has a version associated with it. Check the "Python Interpreter" section of the "Project" section of your Preferences for that. That version is used for syntax highlighting, code completion, etc.
By default, the abovementioned Python version will also be used to run your code. But you can change the version of Python that your code is run with by creating or modifying a Run Configuration. To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.
When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about. You can use this to check to see if Pandas is installed for a particular Python version.
I would suggest you get comfortable with all that I've said above. It will save you many headaches in the future.

Installed module is not working (windows)

So long story short. I want to use requests and bs4 modules in my code. I installed them using pip install requests, pip install bs4. I double checked everything, even found installation folder and saw that the files is here, but my vs code is not detecting it and giving a error. I'm a quite new to this programming language so possibly it's a common issue. But i searched and mostly found posts about this problems on diffrent versions of linux, not windows.
Error i'm getting in vscode btw
Import "requests" could not be resolved from source
And when i'm launching the program through cmd the error is
ModuleNotFoundError: No module named 'requests'
First, you should add more information for us to know how your computer and IDE are configured. The first thing you should do is to check that VS Code is using the Python version where you have pip installed the modules. That is, clicking at the bottom-left space as in the picture below. Then checking that the modules are within that path.
Otherwise, check out virtualenv. With this tool you can create virtual environments within your project's folder and makes it easier to manage packages.

PyCharm: ImportError no module named X?

X in this example represents any module or package you install.
The problem:
I have a problem with a package called 'X'.
In PyCharm I get an error ImportError: No module named 'X'.
My code runs from the terminal without any problem. Any help ?
or
I installed X on python3.4 with pip. In terminal, when I import X, everything is fine, but when I import it in PyCharm, it says: ImportError: No module named 'X'". Any help ?
This is basically everyday question, just with different module or a package instead name instead of X.
And it's not problem in a package or module you install, it's in a PyCharm Project Interpreter you are currently using for your project.
The following answer is usually solution to this specific problem.
SHORTER VERSION:
If you have squiggly line below module you import...
...move on name of module and press Alt+Enter and select Install package X.
This should (probably !!!) install module you thought you installed, but got ImportError.
LONGER:
If you want to use module X:
Go to File -> Settings -> Project:NameOfProject -> Project Interpreter.
The window that opens has some specific regions:
This is a project interpreter PyCharm is currently using. You can change you python environments here also. If you want to add virtual environment you created manually, continue reading.
A little "cog" or a "gear" is used to Add, Edit or Remove environments. If you want to add virtual environment you created manually, select Add... when gear icon is clicked, and make sure to set proper path to python.exeof your virtual environment.
IMPORTANT: A list of all installed packages, represented by: Package name and Version. If you tried to use package, but got ImportError no module named 'X', make sure to check if package is listed here!!!. If not, it's not installed in the current python environment and it should be installed (continue reading).
A little + represents Install. It can be used to install packages. Simply click on + sign, search for a package and click Install Package at the bottom after you found it. You can also specify the version you want of a package. In example below, we searched for flask package.
A package should be installed and listed now in installed packages.
PyCharm creates a virtual environment with its own Python Interpreter for your project, you need to install the module for the interpreter you are using. To do this go to Settings -> Project: yourProjectName -> Python Interpreter, click the plus icon and select the module you would like to install.
Alternatively you could force PyCharm to use your other Interpreter by selecting it from the dropdown at the top of the Python Interpreter settings page I mentioned before.
There are many reasons for this.
The reason and fix I'm going to put here is extremely rare, just decided to put it hoping at least a single person can get help from this answer.
The issue
PyCharm treats __init__.py as a non python file.
This happens when you forgot to use .py extension in your code's __init__.py files, and then you add the extension later. Then pycharm starts treating all __init__.py files (even external library files) as non python. How strange?
Detect if the issue is this
Scroll click on the library name (not the module name).
Or right click and goto Declaration or Usages
You will see the library's __init__.py as plain text.
If you see the code as plain text, that's the issue!
The Solution
Find the file location in pycharm navigation. If you are using virtual environment, the file fill be in venv/lib/site-packages/{library_name}.
Right click on __init__.py, click override file type. Select python.
You'll see the error is gone!

Pycharm won't import Conda module

I'm using Python 3.5 and I was trying to download and use Pillow 4.0.0. I got it through Conda, and it shows in its package menu, as well as the module list in Pycharm. However, even when I have the project interpreter set to anaconda, it will not recognize Pillow at all. I've also given it some time to scan through everything, to see if that would work.
Invalidating the caches and restarting would work. If you want to refresh the Pycharm cache, try going to the far left of PyCharm, and choose [File|Invalidate Caches/Restart...]

Categories

Resources