Can't use pip3 modules: ModuleNotFoundError - python

I leveraged homebrew to install python3 and now I cannot run modules I install with the associated pip3 binary.
from blackduck.HubRestApi import HubInstance
username = "sysadmin"
password = "your-password"
urlbase = "https://ec2-34-201-23-208.compute-1.amazonaws.com"
hub = HubInstance(urlbase, username, password, insecure=True)
Running python3 blackduck.py Results in :
ModuleNotFoundError: No module named 'blackduck.HubRestApi'; 'blackduck' is not a package
Proof of package:
$pip3 install blackduck
Requirement already satisfied: blackduck in /usr/local/lib/python3.7/site-packages (0.0.25)
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (from blackduck) (2.21.0)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (1.24.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (3.0.4)
help('modules') -> contains blackduck
$pip3 list | grep blackduck
blackduck 0.0.25
I've tried to create a virtual environment, to no avail. I also tried adding /usr/local/lib/python3.7/site-packages to my $PYTHONPATH env variable. Thanks in advance!

Don't call your own python script the same as a python module or package - it picks itself up!
From the search-path documentation:
When a module named spam is imported, the interpreter first searches
for a built-in module with that name. If not found, it then searches
for a file named spam.py in a list of directories given by the
variable sys.path. sys.path is initialized from these locations:
The directory containing the input script (or the current directory
when no file is specified).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
The installation-dependent default.
So, all things being equal, the current directory is searched first.
Call it anything else, like my_blackduck.py. I recommend you use a homegrown prefix, maybe a project-code followed by something like an underscore, for development scripts so that you don't repeat the problem.

Related

Python: already install package but can't use (sklearn)

I have already installed sklearn and scikit-learn, the version of sklearn showed 0.0(use pip show instr.)
I've tried many ways to install or update packages, but when I ran the code it shows:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sklearn
ModuleNotFoundError: No module named 'sklearn'
when I install again, it shows:
Requirement already satisfied: sklearn in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (0.0)
Requirement already satisfied: scikit-learn in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from sklearn) (1.0.2)
Requirement already satisfied: numpy>=1.14.6 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.22.3)
Requirement already satisfied: scipy>=1.1.0 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.8.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (3.1.0)
Requirement already satisfied: joblib>=0.11 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.1.0)
can anyone tell me how to deal with it?
thanks!!!
You can check whether the virtual environment installed sklearn is consistent with the one used for your code.
thanks for everyone!
I found that there was the error on the environment variables, it links to old version of python that i havn't deleted, I reinstall python and set the right path, and it works!
You can check which environment you installed that package? Example, with Miniconda, and if I have more than 1 env then I will switch to the specific env, and activate it and install lib.
Then you need to check what env you setup in your development tool (ex: Visual Code).

ModuleNotFoundError: No module named 'ezdxf'

I've installed ezdxf running following library in the same folder that my .py file is located, with this command:
pip install ezdxf
I see this error when hovering on import ezdxf
Import ezdxf could not be resolved Pylance
When I try to run the project it says:
ModuleNotFoundError: No module named 'ezdxf'
I've tried to install again, but I see this:
Requirement already satisfied: ezdxf in c:\users\robert\appdata\local\programs\python\python38\lib\site-packages (0.17.2b1)
Requirement already satisfied: pyparsing>=2.0.1 in c:\users\robert\appdata\local\programs\python\python38\lib\site-packages (from ezdxf) (3.0.6)
Requirement already satisfied: typing_extensions in c:\users\robert\appdata\local\programs\python\python38\lib\site-packages (from ezdxf) (4.0.0)
How could I solve this issue?

torch virtual env not working python 3.7 , what am i doing wrong?

so i installed pytorch using conda into a virtual env while referring to this video
https://www.youtube.com/watch?v=vBfM5l9VK5c
i have activated the env
now inside jupyter notebook i run
import torch
print(torch.__version__)
and it works but when ever i run this in .py file and run it through terminal it gives me this error
import torch
ModuleNotFoundError: No module named 'torch'
if I try to pip install pytorch it says
Requirement already satisfied: torchvision in c:\users\kiit\anaconda3\envs\torch\lib\site-packages (0.10.0)
Requirement already satisfied: numpy in c:\users\kiit\anaconda3\envs\torch\lib\site-packages (from torchvision) (1.20.3)
Requirement already satisfied: torch==1.9.0 in c:\users\kiit\anaconda3\envs\torch\lib\site-packages (from torchvision) (1.9.0)
Requirement already satisfied: pillow>=5.3.0 in c:\users\kiit\anaconda3\envs\torch\lib\site-packages (from torchvision) (8.2.0)
Requirement already satisfied: typing_extensions in c:\users\kiit\anaconda3\envs\torch\lib\site-packages (from torch==1.9.0->torchvision) (3.7.4.3)
so what is going on exactly??
You might have more than one python versions installed on your system i.e One with conda and one separately.
In order to check that, you can go to control panel --> Programs and features. There you can figure out how many python installations are present on your system. Delete the one you dont need and your problem will be resolved.
I found this answer that could be related:
https://stackoverflow.com/a/57753725
Credits to trsvchn for the above answer link.
Perhaps also try opening jupyter notebook from the command line if that doesn't work.

ModuleNotFoundError: No module named 'requests' - can not seem to solve in VS Code (Win 10)

I have looked at similar errors and the fixes I tried have not removed this error (yet).
Package Version
-------------- ---------
beautifulsoup4 4.9.2
certifi 2020.6.20
chardet 3.0.4
idna 2.10
lxml 4.5.2
pip 20.2.3
requests 2.24.0
setuptools 49.2.1
soupsieve 2.0.1
urllib3 1.25.10
There's my current installs which I got from the terminal in VS Code. So, from what I can see, it is all there.
When I run from inside VS Code (the play button top right) I get this error:
[local address of file], line 3, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Further information *edit
I did install requests this way from the VS Code Terminal window:
python -m pip install requests
The output states:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in c:\users\[user]\appdata\roaming\python\python38\site-packages (2.24.0)
Requirement already satisfied: idna<3,>=2.5 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (1.25.10)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (2020.6.20)
Any ideas on fixing this or a set of routine troublecheckers? Thanks kindly
You need to select the python interpreter to be the same of your current environment.
do
which python
/your_path/bin/python
That will give you the path, make sure the Python interpreter on your left button (at VSC) matches the same path, if not make it match.

Cannot import name 'WordCloud'

I am using Jupyter Notebook and trying to build a wordcloud. Turns out there are some issues with the pillow package and the internet is full of talks around it. I was geetting the DLL error initially. I tried a lot of different things and not sure which one worked but right now, I am getting the 'cannot import name' error.
Some details from Anaconda Prompt-
>python -m pip --version
pip 18.0 from C:\Users\Kritika.Jalan\Anaconda3\lib\site-packages\pip (python 3.6)
>python -m pip install wordcloud
Requirement already satisfied: wordcloud in c:\users\kritika.jalan\anaconda3\lib\site-packages (1.5.0)
Requirement already satisfied: numpy>=1.6.1 in c:\users\kritika.jalan\anaconda3\lib\site-packages (from wordcloud) (1.15.0)
Requirement already satisfied: pillow in c:\users\kritika.jalan\anaconda3\lib\site-packages (from wordcloud) (4.0.0)
Requirement already satisfied: olefile in c:\users\kritika.jalan\anaconda3\lib\site-packages (from pillow->wordcloud) (0.45.1)
Details from Jupyter Notebook -
from wordcloud import WordCloud
ImportError: cannot import name 'WordCloud'
import PIL
print(PIL.PILLOW_VERSION)
5.0.0
What am I doing wrong here?
Mostly, having a can not import name error even after successful library installation, is result of conflict with your local file name and python library name.
Do you have your own python file in your local named wordcloud.py ?
If yes, that is causing conflict with wordcloud.py in python library.
Simply rename your script.
Thanks
You just need to change your file name that is same to the library name

Categories

Resources