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

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).

Related

In Jupyter Notebook -- No module named 'pandas'

I'm working in a Windows 10 Enterprise environment. I have been using Jupiter Notebooks successfully for several months, and all of a sudden this morning I'm getting the following error message:
ModuleNotFoundError: No module named 'pandas'
So, I go to my Anaconda cmd prompt and type: pip install pandas
Then, I get this.
(base) C:\Users\RS>pip install pandas
Requirement already satisfied: pandas in c:\users\rs\anaconda3\lib\site-packages (1.4.4)
Requirement already satisfied: python-dateutil>=2.8.1 in c:\users\rs\anaconda3\lib\site-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in c:\users\rs\anaconda3\lib\site-packages (from pandas) (2022.1)
Requirement already satisfied: numpy>=1.18.5 in c:\users\rs\anaconda3\lib\site-packages (from pandas) (1.21.5)
Requirement already satisfied: six>=1.5 in c:\users\rs\anaconda3\lib\site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)
For some weird reason, I have to start the Jupyter Notebook like this 'python -m notebook'. If I just enter 'jupyter notebook' in the Anaconda command prompt, I get this.
(base) C:\Users\RShuell>jupyter notebook
Unable to create process using 'C:\Users\python.exe C:\Users\RS\jupyter-script.py notebook'
Again, everything was working perfectly fine for the last several months, and I'm not sure what changed over the weekend.

ModuleNotFoundError: No module named 'hydra'

I'm trying to run a Python script but it gives an error immediately at the first line of code while trying importing hydra library via:
import hydra
The error i get is the following:
Traceback (most recent call last):
File "C:\Documenti\Python\01 Tool\02_Tool_Archive\calc_risk\src\main.py", line 3, in <module>
import hydra
ModuleNotFoundError: No module named 'hydra'
As the install via right click on the hydra does not work, i tried to google the error and found a possible solution via installing the hydra via pip install from the terminal - this is what i get after calling the pip install again after the first successfull installation:
PS C:\Documenti\Python\01 Tool> pip install hydra-core --upgrade
Requirement already satisfied: hydra-core in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (1.2.0)
Requirement already satisfied: packaging in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (21.3)
Requirement already satisfied: omegaconf~=2.2 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (2.3.0.dev0)
Requirement already satisfied: antlr4-python3-runtime==4.9.* in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from hydra-core) (4.9.3)
Requirement already satisfied: PyYAML>=5.1.0 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from omegaconf~=2.2->hydra-core) (6.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\mhlaca\appdata\local\programs\python\python310\lib\site-packages (from packaging->hydra-core) (3.0.9)
I'm currently stuck. What can I try next? Using Python 3.10.7 and pycharm as IDE, but also tried visual studio - same error.

finnhub installation using pip

I've currently installation of python 3.10 [not conda dist]. I'm trying to import finnhub using both cmd but I'm confronted with the following error message:
C:\Users\Admin>python -m pip install finnhub
ERROR: Could not find a version that satisfies the requirement finnhub (from versions: none)
ERROR: No matching distribution found for finnhub
Any ideas on what I'm missing please? I've also tried to install this package using PyCharm but this results in the following error:
C:\Users\Admin\PycharmProjects\NewPython\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/NewPython/main.py
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\NewPython\main.py", line 1, in <module>
import finnhub
ModuleNotFoundError: No module named 'finnhub'
Process finished with exit code 1
I have added the python installation to PATH and the current version of pip is the latest version.
Many thanks in advance for your help.
Question update
In the meantime, I have spotted an old environment reference which has been now removed. This seems to allow the install of finnhub using
pip install finnhub--python
but not
pip install finnhub
Code below:
C:\Users\Admin>pip install finnhub
ERROR: Could not find a version that satisfies the requirement finnhub (from versions: none)
ERROR: No matching distribution found for finnhub
C:\Users\Admin>pip install finnhub--python
Requirement already satisfied: finnhub--python in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (2.4.13)
Requirement already satisfied: requests>=2.22.0 in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (from finnhub--python) (2.28.1)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (from requests>=2.22.0->finnhub--python) (1.26.10)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (from requests>=2.22.0->finnhub--python) (2022.6.15)
Requirement already satisfied: idna<4,>=2.5 in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (from requests>=2.22.0->finnhub--python) (3.3)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (from requests>=2.22.0->finnhub--python) (2.1.0)
C:\Users\Admin>
When using PyCharm to try to access this from the IDE, I am now confronted with:
C:\Users\Admin\PycharmProjects\pythonProject2\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/pythonProject2/main.py
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\pythonProject2\main.py", line 1, in <module>
import finnhub
ModuleNotFoundError: No module named 'finnhub'
Process finished with exit code 1
From the the section "Installation" of the package's documentation:
pip install finnhub-python
In this command, it becomes clear that you have installed finhub globally,
C:\Users\Admin>pip install finnhub--python
Requirement already satisfied: finnhub--python in c:\users\admin\appdata\local\programs\python\python310\lib\site-packages (2.4.13)
But when running your script your command looks like this
C:\Users\Admin\PycharmProjects\NewPython\venv\Scripts\python.exe C:/Users/Admin/PycharmProjects/NewPython/main.py
So you are using a virtual environment for your project in which finnhub is probably not installed yet.
Try:
C:\Users\Admin\PycharmProjects\NewPython\venv\Scripts\python.exe -m pip install finnhub-python
Alternatively, you can use pycharm as well
With your project open go to File
Select Settings->Project->Python Interpreter
You should see a list of packages and their version. Hit the little + button above it
Search for finnhub-python, select it and hit Install Package

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.

Categories

Resources