pip install cmd but modules not found in PyCharm - python

So, I have Pycharm and pip up to date, and after installing any module with pip install, no matter where I install it (/current_python_project) or somewhere else (\python310\lib\site-packages)...
When I pip install let's say pandas, and then try
import matplotlib.pyplot as plt
console says: ModuleNotFoundError: No module named 'matplotlib'
This happens with other packages here the package is installed but modules or ".py" files form installation, are not found.
Thank you!
I tried installing in different folders and changing virtual environment setting to all possible combinations but yet, I still can't fix the problem...
Checked docents of "answers" to similar problems
Also I checked one more answer here it says I have to install in env/bin/python but I searched for all folders containing "env" and apparently I don't have this folder....

Please try the following instructions:
python -m pip install – upgrade pip
pip install pandas
pip install matplotlib
Or you can try following instructios:
open cmd, and type "where python". Once you have opened the Python folder, browse and open the Scripts folder and copy its location. Also verify that the folder contains the pip file.Now open the Scripts directory in the command prompt using the cd command and the location that you copied previously.Now install the library using pip install matplotlib command. If it looks complicated please follow this link, they show with illustrations: https://blog.finxter.com/fixed-modulenotfounderror-no-module-named-matplotlib/

Related

Import numpy can't be resolved ERROR When I already have numpy installed

I am trying to run my chatbot that I created with python, but I keep getting this error that I don't have numpy installed, but I do have it installed and whenever I try to install it it tells me that it is already installed. The error reads "ModuleNotFoundError: No module named 'numpy'"
I don't understand what the problem is, why is it always throwing this error? even for nltk and tensorflow even though I have them all installed.
How can I resolve this issue?
Here is a screen shot when i install numpy:
Here is a screen shot of the error:
I fixed the problem by deleting a python folder that was in the root directory of C:/ which caused installing the package to be ignored and not be installed in the correct directory which is in C:/Users/
This is not a very correct decision, but I had same problem with another libraries. You can be using different python interpreters (in my case it was anaconda) => libraries can be installed in different folders
It was a temporarly solution, but I created new venv
pip install virtualenv
mkdir python-virtual-environments && cd python-virtual-environments
python3 -m venv env
source env/bin/activate # activate venv
There you can install all packages for your project, and deactivate it (with deactivate) command

How to resolve Python import module?

I'm on Ubuntu 20.4. When I execute a Python script, I get the following error and sys.path.
I installed the packages with pip3 and they are located in
/usr/local/lib/python3.8/dist-packages
When I look at the installed packages for python3 and python3.8 interpreter, I see "binance" package installed and recognized.
I tried to set PYTHONPATH to point to my project folder, but that didn't help either.
echo $PYTHONPATH --> /algos_python
You have installed binance from PYPI but you are not using it. You are using python-binance and you need to install it. (Using python3 -m pip install python-binance) and then run your code again. See this for more info on this.
Try these:
python3 -m pip install python-binance
If you are calling your file binance.py (Or have a file/folder named that in your directory), and then trying to import from binance.client, python will look in your binance.py file instead of the library. So try renaming your local file.

How to fix "ImportError: DLL load failed" while importing win32api

I'm setting up an autoclicker in Python 3.8 and I need win32api for GetAsyncKeyState but it always gives me this error:
>>> import win32api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing win32api: The specified module could not be found.
I'm on Windows 10 Home 64x. I've already tried
pip install pypiwin32
And it successfully installs but nothing changes. I tried uninstalling and re-installing python as well. I also tried installing 'django' in the same way and it actually works when I import django, so I think it's a win32api issue only.
>>> import win32api
I expect the output to be none, but the actual output is always that error ^^
Solved
If you are working in a miniconda on conda environment. You could just install pywin32 using conda instead of pip.
This solved my problem:
conda install pywin32
For my case, install and reinstall pywin32 doesn't help. After copied the two files from [installation directory of Anaconda]\Lib\site-packages\pywin32_system32 to C:\Windows\System32, it works.
My environment is python 3.8 in miniconda. The two files are pythoncom38.dll and pywintypes38.dll.
For me, it worked by downgrading my pywin32 from version 227 to version 224. Just type the following command on any shell in administrator mode:
pip install --upgrade pywin32==224
Run Scripts\pywin32_postinstall.py -install in an Admin command prompt
ref: https://github.com/mhammond/pywin32/issues/1431
edit: User #JoyfulPanda gave a warning:
Running this script with admin rights will also copy pythoncom37.dll, pywintypes37.dll (corresponding to the pywin32 version), into C:\WINDOWS\system32, which effectively overwrites the corresponding DLL versions from Anaconda already there. This later causes problem when openning (on Windows) "Start Menu > Anaconda3 (64-bit) > Anaconda Prompt (a_virtual_env_name)". At least Anaconda 2019.07 has pywin32 223 installed by default. Pywin32 224 may work, but 225-228 causes problem for Anaconda (2019.07)
The answer is in jupyter notebook github.
https://github.com/jupyter/notebook/issues/4980
conda install pywin32 worked for me. I am using conda distribution and my virtual env is using Python 3.8
This happens when Lib\site-packages\pywin32_system32 is not in the list of directories to search for DLL (PATH environment variable).
pywin32 (or one of its dependencies) adds this path at runtime to the PATH variable. If this is failing, or another component is overriding the PATH after it's been set by pywin32, you will get the given error (ImportError: DLL load failed while importing win32api).
You can try to extend the PATH variable in the shell before starting Python.
On Windows:
set PATH=c:\...\Lib\site-packages\pywin32_system32;%PATH%
If that doesn't work, then the PATH maybe overridden within the Python program at runtime. Add the following line to your program just before pywin32 is used to verify its value:
import os
print(os.environ["PATH"])
As a last resort, you can extend the PATH variable before pywin32 is loaded:
Windows:
os.environ["PATH"] = r"c:\...\pywin32_system32;" + os.environ["PATH"]
Unix like:
os.environ["PATH"] = r"/.../pywin32_system32:" + os.environ["PATH"]
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python path\to\python\Scripts\pywin32_postinstall.py -install
taken from here. worked for me!
For python 3.8.3, pywin32==225 worked for me, the existing pywin32==228 was uninstalled.
So try this
pip install pywin32==225
Hope it solves your problem
What helped me was
installing relevant binary from github.com/mhammond/pywin32
executing the following commands in the x64 command line:
cd C:\ProgramData\Anaconda3\Scripts
python pywin32_postinstall.py -install
As of February 2022, downgrading tot version 303 of pywin32 solves the issue.
Check your pywin32 version:
pip show pywin32
Downgrade to version 300:
pip install pywin32==300 --upgrade
Restart Jupyter
pypiwin32 is an outdated distribution. Uninstall it and install pywin32:
pip uninstall pypiwin32
pip install pywin32
You should try some (or all) of my methods:
Run terminal and use this command: conda install pywin32.
Copying the two files from [installation directory of Anaconda]\Lib\site-packages\pywin32_system32 (there are only 2 files in this folder) and paste to C:\Windows\System32.
In my case, the two files are pythoncom38.dll and pywintypes38.dll (it means my Python version is 3.8).
Downgrading the version of pywin32 to 225 or lower by this command: pip install pywin32==225.
Windows 10, Python 3.8, PyWin32 v.302 using Anaconda
Here is what worked for me
Open an elevated command prompt activate environment
Windows Key
Type cmd
Right click Command Prompt and click Run as Administrator
conda activate [ENVIRONMENT]
Navigate to the environment you installed PyWin32 on, works if pip install or conda install is used
cd C:\Users\[USER]\anaconda3\envs\[ENVIRONMENT]\Scripts
Run the post install script that was added when installing PyWin32
python pywin32_postinstall.py -install
Yes it works!
C:\ProgramData\Anaconda3>py Scripts\pywin32_postinstall.py -install
Parsed arguments are: Namespace(destination='C:\ProgramData\Anaconda3\Lib\site-packages', install=True, quiet=False, remove=False, silent=False, wait=None)
Copied pythoncom38.dll to C:\WINDOWS\system32\pythoncom38.dll
Copied pywintypes38.dll to C:\WINDOWS\system32\pywintypes38.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore\3.8\Help[None]=None
-> Software\Python\PythonCore\3.8\Help\Pythonwin Reference[None]='C:\ProgramData\Anaconda3\Lib\site-packages\PyWin32.chm'
Registered help file
Pythonwin has been registered in context menu
Creating directory C:\ProgramData\Anaconda3\Lib\site-packages\win32com\gen_py
Can't install shortcuts - 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 3.8' is not a folder
The pywin32 extensions were successfully installed.
version 228 works best for me in Windows 10
pip uninstall pywin32
pip install pywin32==228
Jupyter notebook github has the issue mentioned in the question. There are multiple solution proposed.
What worked for me was this answer with additional first step:
pip uninstall pywin32
pip install pywin32
python [environment path]/Scripts/pywin32_postinstall.py -install
In the referecne to this comment question
where is this Lib\site-packages\pywin32_system32 path?
Go to C directory, Users , your username , anaconda3 ,Lib, site-packages,pywin32_system32. you can find easily.
C:\Users\HP\anaconda3\Lib\site-packages\pywin32_system32
Currently there are two copies of the pythoncom*.dll files in directories.
Pycharm is using the copy in directory C:\Windows\System32:-
C:\Windows\System32
C:\Users\sharandi\AppData\Local\Programs\Python\Python38\Lib\site-packages\pywin32_system32
The files are: -
pythoncom38.dll - 559 KB
pywintypes38.dll - 138 KB
I downloaded and installed the latest Microsoft Visual C++ 2015-2019 package from
(https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads). You may have to restart your machine after installation.
Then from conda command prompt activate your virtual environment and go to the Scripts folder of the virtual environment(>cd "path of venv"/Scripts)
Once you are in the Scripts folder run the following command
"python pywin32_postinstall.py -install"
This will install the required dll's to the appropriate folders in the virtual environment.
And that's how I got it to work!
I have had this issue with Jupyter in Anaconda. After following all listed advices, without clear understanding what I am doing, nothing worked for me except one thing. I have updated indexes of Anaconda environments and I've got my kernels back. The screenshot
This problem for me occured when recreating venv from requirements.txt. This venv was initially created on Ubuntu Linux and then recreated on Win 10.
I had to clear the environment and install everyrhing again manually. Did the work for me.
Solved
I tried uninstalling and reinstalling pywin32 multiple ways, but the problem persisted. The following way solved the problem:
pip install --upgrade jupyter_client
pip install --upgrade pywin32==224 --force-reinstall
hi this question i'm solve as below:
1.check directory C:\Windows\System32, is exist these file?
pythoncom37.dll pywintypes37.dll or pythoncom36.dll pywintypes36.dll
the number is python version .
if the file is exist delete it.
and then this issue will be solve.
You should go into the folder {python folder path}/Lib/site-packages/pywin32_system32 and copy pythoncomXX.dll and pywintypesXX.dll to the folder C:/Windows/System32.
If you are using a virtual environment, then {python folder path} is the python folder used by the virtual environment, otherwise it is the folder where the global python is located. For example, I use conda to create a virtual environment called Frameless-Window, and install the package pywin32 in this virtual environment, then the {python folder path} on my computer should be D:/Anaconda/envs/Frameless-Window.
You should be very careful when copying the dll to the System32 folder. if there are dlls with the same name in the folder and pywin32 in your other virtual environment may use these two dlls, replacing the original dlls may cause this virtual environment had the same ImportError problem. After testing, I found that the dlls of pywin32 of version 227, 228 and 300 can be replaced with each other, and the dlls of pywin32 of versions 301, 302, 303 and 304 can also be replaced with each other, but if the dll of version 300 is replaced with the dll of version 301, it will raise ImportError.
If you are launching a virtual env from another virutal env. Makes sure to install pywin32 in both envs. Lost way too many time with this....
This worked for me
conda install -c anaconda pywin32
Its about venv or virtualenv version problem about pywin32
check version of both of version of pywin32 (pip install pywin32)
than run this command on active venv
pip install --upgrade pywin32==305
Maybe a bit late but it could help:
What happens is that you have two versions of pywin32 installed (One in the local enviroment and the other one in the main python installation)
To solve that uninstall both versions with:
conda uninstall pywin32
pip uninstall pywin32
And inside your virtual conda enviroment also execute:
conda uninstall pywin32
or
pip uninstall pywin32
finally in your virtual enviroment / conda enviroment install with pip install pywin32 or conda.
The answers telling that it works with x version is because the version they install are compatible with the pywin32 dlls they have in system32.
Adding a support link: "DLL load failed: The specified procedure could not be found" when importing win32api or win32com
I had the same issue after reinstalling anaconda 3.9 instead of 3.7 and placing inside the former env folder.
I launched the Anaconda Prompt application then typed in
cd C:\Users\%USERNAME%\anaconda3\Scripts
activate.bat
I suspect it updated the pythoncomXX.dll and pywintypesXX.dll used by anaconda.
That is Simple. After Many Tries, I Discovered a Solution. Just Type the Following Commands in Windows 10. I am Using Pycharm, Python Version 3.9
Note:- This Works for All Python Versions !!
pip uninstall pywin32
pip install pywin32
That is Simple.
if That Does Not Work, Then Try:-
pip uninstall win32api
pip install win32api
After Trying These Commands, Try the first 2 commands again.
If It is Still Not Coming, Then Comment This Question What the problem is !!

No module named livelossplot

I have recently tried to make some realtime plots for my Ml models.
I have installed livelossplot through this command:
pip install livelossplot
But, when trying to import the module in Jupyter, it returns error:
ModuleNotFoundError: No module named 'livelossplot'
Please,
can someone help me?
You can try this
pip install livelossplot==0.1.2
Refer the below link
https://pypi.org/project/livelossplot/0.1.2/
If it doesn't work then you can clone the below repository
https://github.com/stared/livelossplot
Well there are a couple of ways to go about this problem one way is to start anaconda-navigator
left click on the play type button there in the (base)root environment and select open in terminal
and then simply type
pip install livelossplot
One another method is if you have added anaconda path to you PATH variable in linux or environment variable in WINDOWS then you can log into the environment
like
albin#computer:~$ source activate
(base) albin#computer:~$ pip install livelossplot
if you havent added to the PATH or environment variable then you can log into the enviroment by specifying the full path like
albin#computer:~$ source anaconda3/bin/activate
(base) albin#computer:~$ pip install livelossplot

Pythonpath is still ignored and unable to install locally with pip

I'm finding that my pythonpath environment variable is ignored. I'm using python 2.6 on ubuntu. I have in my .bashrc the following:
export PTYHONPATH=/my/home/mylibs/lib/python2.6/site-packages/:$PYTHONPATH
Then I install a new version of numpy using:
python setup.py install --prefix=/my/home/mylibs/
and it gets correctly installed locally. However, when I try to install other packages (also using setup.py) that depend on the new version of numpy, they cannot find it, because by default the loaded numpy is the one in /usr/llib, and not the one specified in my PYTHONPATH. My PYTHONPATH gets correctly set but the system-wide directory is still overruling it.
How can this be fixed? I just want my local version of numpy to be accessed when I do import numpy. I saw other posts related to this with python 2.4 but as far as I can tell it never got resolved. Also, i'd like to do this without installing pip or virtualenv for now. It seems like it should be possible using --prefix or --home options passed to setup.py and then alteration of PYTHONPATH but this does not work for me... the system wide lib dirs are read first.
edit: I try to follow the suggestions and use pip. I have a system wide install of an old pip that does not recognize --user (ver 0.3). I tried to upgrade pip with pip itself but of course that failed because I cannot install it locally, so pip install pip --upgrade --user is not an option. I downloaded a new version of pip and installed locally in my home directory but the system wide old one is still used when I type pip at the prompt. I looked into the pip package and found runner.py so I tried to use it to install packages using:
runner.py install --user numpy --upgrade
That still fails with permission denied:
OSError: [Errno 13] Permission denied: '/usr/bin/f2py2.6'
It looks like --user is broken. I also am not sure how this would solve the fact that the system wide python uses the system wide packages in /usr/lib... is there a solution to this? It seems like it's virtually impossible to install local packages in python nowadays.
Ok, Python will use the first package it finds. The PYTHONPATH gets appended to sys.path, after the system one. So it will normally find the system one first. But the "official" per-user packages directory seems to be placed before that. So create your personal site-packages directory:
mkdir -p $HOME/.local/lib64/python2.7/site-packages
mkdir $HOME/bin
(You may have to change "lib64" to "lib32" or just "lib")
This directory gets placed before the system one on my system. But you should verify it by printing out sys.path.
Then install your packages into there. However, the --user option in the latest pip version should already place it there.
As a list resort you can manipulate sys.path. You can insert your directory into sys.path before the system site-packages, then import numpy.
You are getting permissions errors from the scripts installation, trying to put that in the system location. You can pass additional options to install scripts in your $HOME/bin directory.
Install like this:
pip install --user --install-option="--install-scripts=$HOME/bin"

Categories

Resources