0

I'm teaching myself python and have been exclusively been using Jupyter Notebooks through Anaconda until now. I'm now trying to move away from Jupyter and write .py scripts in an IDE. While working in Jupyter i've pip installed modules and they've worked fine within Jupyter. I've just discovered though that if i do this through an IDE i get a ModuleNotFoundError.

I've looked online and there are alot of posts with similar issues but none that quite matches mine. While i'm learning actual python code ok there is a huge hole in my knowledge around the setup, the terminal etc, and when i first started out i downloaded different IDE's which may not be helping...

Here's a few things from posts that i've tried that may give a clue as to what's wrong.

1) which python gives me //anaconda3/bin/python

2) which pip gives me //anaconda3/bin/pip

3) in python in the terminal:

import sys
for p in sys.path:
    print(p)
//anaconda3/lib/python37.zip
//anaconda3/lib/python3.7
//anaconda3/lib/python3.7/lib-dynload
//anaconda3/lib/python3.7/site-packages
//anaconda3/lib/python3.7/site-packages/aeosa

4) usr/local/bin/ has a bunch of files (not folders) in it like 'Python3.7', 'Python3.7-config' etc

5) which -a pip = //anaconda3/bin/pip

6) which -a python gives me two paths = //anaconda3/bin/python /usr/bin/python

7) usr/bin/python is a unix executable file, when i click it it opens a python terminal that says Python 2.7.16. within the usr/bin directory all the other python related files seem to reference 2.7.

8) when i pip install i generally just go 'pip install x' at the terminal. I thought maybe i needed to do 'pip3 install x' it would maybe not point just to anaconda, but was a complete guess and while the modules downloaded it didn't help at all.

9) I tried using an alias alias python=/usr/local/bin/python3 - but as python3 isn't actually there, i just created another problem that i then had to 'unalias'

10) pip -V = pip 19.1.1 from //anaconda3/lib/python3.7/site-packages/pip (python 3.7)

11) pip freeze showed the all the modules i would expect to see

This post seemed similar: Modules are installed using pip on OSX but not found when importing

Any help would be greatly, greatly appreciated. I've been learning ok up until now but i'm pretty out of my depth with this side of things, and i can't move forward at all unless i find a way to use an IDE with third party modules...

UPDATE - Tried uninstalling and reinstalling anaconda and it made no difference. All still works in Jupyter, modules can't be found elsewhere from IDEs. Also can't seem to install things like pandas through anaconda as it already has it, so it doesn't seem related to the IDE not being able to find it –

Thanks

GlassShark1
  • 153
  • 1
  • 13

1 Answers1

0
  1. When using the Anaconda distribution you should avoid pip as much as possible. Use the conda package manager instead. Try installing missing packages from the conda-forge channel first:

    conda install newpackage -c conda-forge
    
  2. Before you can use Anaconda properly, you need to activate it:

    conda activate
    

    The Jupyter start link did this for you. The Anaconda Prompt does the same thing and you can start your IDE directly from there. However, all IDE's manage environments themselfs, which is way more flexible. So it is time well spent to learn your IDE's features first.

Peter
  • 10,959
  • 2
  • 30
  • 47
  • ok I tried conda install pandas -c conda forge as an example. Amongst other bits, i got: "The environment is inconsistent, please check the package plan carefully The following packages are causing the inconsistency: - defaults/osx-64::anaconda==2019.07=py37_0 - defaults/osx-64::numba==0.44.1=py37h6440ff4_0" - then i got 'The following packages will be DOWNGRADED - Anaconda -2019.07-py37_0 --> custom-py37_1 proceed (which i did). Now it says permission denied [Errno 13] Permission denied: '/usr/local/bin/.cph_tmpcidus4o9' [Errno 13] Permission denied: '/usr/local/bin/.cph_tmpyxrvwv0k' – GlassShark1 Apr 05 '20 at 10:06
  • This is exactly what happens when mixing pip and conda. I'd recommend a fresh Anaconda install - and don't change the default settings! – Peter Apr 05 '20 at 10:11
  • If i uninstall / reinstall it i'm presuming i'll lose all my notebook scripts. I'm terrified of this as it's all the work i've ever done. I can c&p it all out into .txt files i guess... – GlassShark1 Apr 05 '20 at 10:21
  • it is very appreciated i promise you – GlassShark1 Apr 05 '20 at 10:31
  • just to say i tried uninstalling and reinstalling anaconda and it made no difference.All still works in Jupyter, modules can't be found elsewhere from IDEs. Also can't seem to install things like pandas through anaconda as it already has it, so it doesn't seem related to the IDE not being able to find it – GlassShark1 Apr 05 '20 at 12:16
  • No surprise at all. – Peter Apr 05 '20 at 15:24
  • well thanks - tried to follow your advice (and it was appreciated) and now you say no surprise at all? – GlassShark1 Apr 06 '20 at 11:48