0

I have noticed that when I install new modules using pip install example, it installs correctly but when I try importing it in a script it says: ModuleNotFoundError: No module named 'example'. To get the modules working I have to copy the module's folder to the directory of my script. Before this started happening I had installed some modules which also work now so I'm a bit confused.

I'm guessing that there's something wrong with some PATH but I'm not really sure. How can I fix this?

Edit: I'm almost 100% sure that these problems started happening when I installed Anaconda. I have made sure Anaconda's folder is added to PATH but I still have the same issue.

Jimminer
  • 3
  • 3

1 Answers1

0

With Anaconda, you would benefit from installing new packages by conda install example instead of using pip.

However, it is likely that you have installed another copy of Python that comes with Anaconda, and you should check which Python you are using by typing python -V in your command prompt or checking where it is installed (for Windows machines, check here). You might have installed the package to use with one version of Python, but your system directed you to the other one.

I have uninstalled my standalone Python distribution after installing Anaconda, so my default version of Python is the version that comes with Anaconda.

  • I have python 3.8.5 and when I run `where python` in cmd I got: ```C:\Users\Jimminer\anaconda3\python.exe C:\Users\Jimminer\AppData\Local\Programs\Python\Python39\python.exe C:\Users\Jimminer\AppData\Local\Microsoft\WindowsApps\python.exe``` – Jimminer Jan 21 '21 at 10:59
  • Looks like you have three versions of Python installed on your computer, and I will assume that the Anaconda version is the one you would like to use. In that case, the Anaconda version should be on the top of the list in PATH. I would assume then pip would be installing to this version of Python (else `Jimminer\anaconda3\python -m pip install example` might work). In any case, `conda install example` should help, and I wonder if you have tried it. Also, I'm not sure if you need to configure your editor to work with Anaconda. Would you care to share which editor you are using for Python? – Life is Good Jan 21 '21 at 15:12
  • Not gonna lie, I'm still using Notepad++ lol. I haven't used any other editor although I'm looking forward to do so. What would you recommend? – Jimminer Jan 21 '21 at 20:29
  • I actually have no idea what is a good editor. I have used IDLE, PyCharm, but now I am using Jupyter notebook because it is good for displaying dataframes for data manipulation. For Jupyter notebook, I use Anaconda prompt, so I am automatically using Anaconda's Python. For Notepad++, it seems to be rather straightforward to choose the Python that you work with based on what I found [here](https://stackoverflow.com/questions/1702586/how-to-execute-a-python-file-in-notepad), but you are probably rather familiar with it already. – Life is Good Jan 21 '21 at 20:38
  • Ok I will try those editors you talked about. About the path of anaconda, Anaconda is the first entry in my path but the error still exists. – Jimminer Jan 21 '21 at 22:39
  • If the error persists even after you type `conda install example`, it might be a problem with environments. i.e., you have installed the packages into one environment, but you are using another environment? – Life is Good Jan 21 '21 at 22:47
  • Your suggested command didn't work. I got an output of `All requested packages already installed.` and I got the same error again. Also, to be completely honest I don't even remember why I installed conda. I think it was a dependency for a module but I essentially didn't know what it was. – Jimminer Jan 21 '21 at 23:16
  • You know what, I also don't remember why I installed Anaconda. Here is one more thing I remembered: did you check where you installed the package, and verify that it is in a folder that is in your path? Refer to [here](https://stackoverflow.com/questions/43485569/installed-a-package-with-anaconda-cant-import-in-python) for more details. – Life is Good Jan 22 '21 at 03:41
  • Every package that I installed seems to be in the folder `C:\Users\Jimminer\anaconda3\Lib\site-packages` My path's order from top to bottom is like this: `C:\Users\Jimminer\anaconda3`, `C:\Users\Jimminer\anaconda3\Library\mingw-w64\bin`, `C:\Users\Jimminer\anaconda3\Library\usr\bin`, `C:\Users\Jimminer\anaconda3\Library\bin`, `C:\Users\Jimminer\anaconda3\Scripts`, `C:\Users\Jimminer\AppData\Local\Programs\Python\Python39\Scripts\ `, `C:\Users\Jimminer\AppData\Local\Programs\Python\Python39\ ` – Jimminer Jan 22 '21 at 19:46
  • I believe I also included this folder `C:\Users\Jimminer\anaconda3\Lib\site-packages`, with my name in it, of course. – Life is Good Jan 22 '21 at 20:11
  • I tried adding it to my path but nothing changed. When I run `conda list` the modules I need are listed there so that might mean that the conda enviroment is not used even though it's at the top of my path. – Jimminer Jan 23 '21 at 00:00