0

I am having a problem with this code. I am using Jupytor notebook and my code is as follows:

from sklearn.preprocessing import MinMaxScaler

Error I am having is:

ModuleNotFoundError: No module named 'sklearn'

I have tried using the following line of codes in order to import sklearn but it's still giving me the same error:

  1. pip install -U scikit-learn
  2. pip3 install sklearn
  3. pip install sklearn

Can anyone please help me out with this? I have tried every possible thing in my jupyter notebook still I couldn't resolve my error

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Hania Salman
  • 21
  • 1
  • 8
  • 1- what system are you running this one ? Windows, Windows + WSL, Mac ? 2- how do you start your jupyter notebook. Anaconda ? Command line ? If you answer these I'll know exactly what commands you need to use. It is not advisable to run these commands if you don't know how many environments you have or how your python is installed. – hussam Dec 05 '20 at 21:04
  • Are you using Conda or Venv? – Amin Gheibi Dec 05 '20 at 21:04
  • Does [this](https://stackoverflow.com/questions/8663046/how-to-install-a-python-package-from-within-ipython) answer your question? – ssp Dec 05 '20 at 21:05
  • @Moosefeather she's new to this, don't throw her in the deep end. – hussam Dec 05 '20 at 21:07
  • @hussam I am using command prompt to run my jupyter notebook and I'm using windows – Hania Salman Dec 05 '20 at 21:14
  • @Moosefeather I have also tried installing it using !pip install sklearn. i have done everything but still all in vain – Hania Salman Dec 05 '20 at 21:16
  • 1
    Sometimes when using `pip install`, `pip` will point to a different python. To check, compare the output of `pip -V` with your `sys.path` in your notebook. If they don't match, you will want to use `python -m pip install `, which will use the same `python` you use to run scripts – C.Nivs Dec 05 '20 at 21:26
  • Are you using Anaconda/Conda ? if you want to know run the following command in command line `conda env list`. This should list the python environment names(s). – hussam Dec 05 '20 at 21:31
  • @hussam i am new to this python and I am simply using cmd to run my J.notebook. The command you told is giving me error that 'conda' is not recognized as an internal or external command, operable program or batch file. – Hania Salman Dec 05 '20 at 21:40
  • This means that you do not have conda/anaconda installed. You have native python install. Which is problematic for data science in general because you'll have to maintain the consistency of the packages yourself. now try: `python -m pip install scikit-learn` – hussam Dec 05 '20 at 22:06
  • is it necessary to install anaconda with python? – Hania Salman Dec 06 '20 at 09:49
  • @hussam the above command is giving me so many errors ERROR: Could not install packages due to an EnvironmentError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:' WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available. You should consider upgrading via the 'C:\Users\Windows 10\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip' command. – Hania Salman Dec 06 '20 at 10:01
  • 1
    you can try to upgrade pip using `-m pip install --upgrade pip` but environment errors are silly... Best is to uninstall whatever you have on your system. Using windows add/remove programs, remove the current python installation. Make sure that it is gone, you can confirm by running the command `python` in your command line after the uninstall. You should get that the command is not recognized. Then go to this link, https://docs.conda.io/en/latest/miniconda.html and download the windows 64 Miniconda python3.8 (not anaconda) and install it. It is a regular install. Drop a line when done. – hussam Dec 06 '20 at 20:13
  • 1
    Thankyou @hussam for all this information. I have now installed anaconda and I have imported all the libraries i.e NumPy, pandas, matplotlib, and more importantly sklearn and scikit-learn and its all done without having any error. So yeah I'll be using anaconda from now on. Thank you for helping me this much. – Hania Salman Dec 06 '20 at 21:00
  • 1
    Happy to help!. Here's another helpful tip, create different python environments for different tasks using the following command `conda create -n python=3.8`. Choose a name you like. You can switch between environments using `conda activate `. For example, if you want to scrape the web, scraping packages might have conflicts with modling packages, so you can create a new env rather than overloading a single env with so many packages. Each environment is independent and they don't take too much space. Best of luck. – hussam Dec 07 '20 at 01:58
  • I will, Thanks for all the Help @hussam – Hania Salman Dec 07 '20 at 17:40

0 Answers0