0

I have some troubles with pip install and I am new to python:

First, this is my python version:

(base) becker@tsf-436-wpa-5-126 ~ % which python3
 /Users/becker/opt/anaconda3/bin/python3

then for example I want to install turfpy, so I do

 pip3 install turfpy

the output to that is

  Requirement already satisfied: turfpy in ./opt/anaconda3/lib/python3.8/site-packages (0.0.6)
  Requirement already satisfied: shapely in ./opt/anaconda3/lib/python3.8/site-packages (from turfpy) (1.7.1)
   Requirement already satisfied: scipy in ./opt/anaconda3/lib/python3.8/site-packages (from turfpy) (1.5.2)
   Requirement already satisfied: numpy in ./opt/anaconda3/lib/python3.8/site-packages (from turfpy) (1.19.2)
   Requirement already satisfied: geojson in ./opt/anaconda3/lib/python3.8/site-packages (from turfpy) (2.5.0)

So In principle, I would assume that everything should work.

Now my python file that I am writing with spyder is in a different folder, you see the directory below, than any of the above.

In fact, running the file, I get

  File "/Users/becker/Desktop/elevation data/pointinpolygon.py", line 1, in <module>
    from turfpy.measurement import boolean_point_in_polygon

   ModuleNotFoundError: No module named 'turfpy'

So I must assume that turfpy is not installed after all.

I apologize in advance if some additional information is missing that I should provide. I am a bit clueless what is going on. However, I would like to understand how to do it with spyder and not first uninstall everything to fix this issue, if that is possible.

J.Doe
  • 181
  • 1
  • 8
  • Try “pip3 install xyz”. Then try “python3 file.py” – BlackFox Apr 13 '21 at 10:25
  • i understand the first command, and it produced the same output as pip install xyz, i do not see where you want me to use the second one. I use spyder. Sorry, I am completely new to python. So without doing the second one, it did not work I think as I still get 'module not found' – J.Doe Apr 13 '21 at 10:28
  • When you install for non microsoft systems....you can create 2 bin folders. One will be python2 and be labeled python. The other will be python3 and will be labeled python3. When you use python2 the command will be “python filename.py”. When you use python3 the command will be python3 filename.py. – BlackFox Apr 13 '21 at 10:31
  • When you use pip for python2 your command will by pip install xyz. When you use python3 the command would be pip3 install xyz. – BlackFox Apr 13 '21 at 10:32
  • Next fix your folder name: elevation data....call it elevation_data or ElevationData – BlackFox Apr 13 '21 at 10:35
  • Elevation Data is only a folder, actually. But I am still confused. I tried the pip3 install turfpy command. And then I ran my little program again. The complaint was still the same – J.Doe Apr 13 '21 at 10:36
  • Ya you have a lot to learn here...but its cool...folder names with space will not work many times.... – BlackFox Apr 13 '21 at 10:38
  • What is your run command for python? Did you try “python3 yourscriptname.py” – BlackFox Apr 13 '21 at 10:39
  • Also, stop using spider...uses VS code...simple to understand what’s going on – BlackFox Apr 13 '21 at 10:39
  • When you get it working....uninstall andiconda ..then reinstall for python3... https://docs.anaconda.com/anaconda/user-guide/tasks/integration/python-vsc/ – BlackFox Apr 13 '21 at 10:42
  • When you understand how to get python2 and python3 working in vs code...and how to install dependencies for each ...then you can focus on understanding how to install andiconda..finally you can try to understand how to use and install python2 and python3 for spider..and how to install dependencies....there are levels to this ish – BlackFox Apr 13 '21 at 10:49
  • well, I would still like to fix it first using my spider environment. – J.Doe Apr 13 '21 at 12:32
  • 1
    I'd guess, that you're not using the same python in the anaconda prompt as in spyder. Try to type "python" in the anaconda prompt and then do "import turfpy". Does it work? – Mike S Apr 13 '21 at 12:37
  • This might have to do with spyder not using the `base` conda environment. – astrochun Apr 13 '21 at 12:42
  • So if I enter python in my terminal I get: (base) becker@tsf-436-wpa-5-126 ~ % python Python 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. – J.Doe Apr 13 '21 at 12:44
  • I am confused. How do I change to the correct python in spider then? – J.Doe Apr 13 '21 at 12:45
  • 1
    How do you start sypder? Try to start it from command line. Then it should start in the base environment. – Mike S Apr 13 '21 at 12:45
  • great, that worked. what a magic...thank you! – J.Doe Apr 13 '21 at 12:51

1 Answers1

1

Make sure, that your Spyder is using the "base" anaconda environment.

From: https://docs.spyder-ide.org/current/faq.html :
In the anaconda prompt: You should activate your conda environment (in your case you don't have to, since you use the "base" environment) and start spyder typing "spyder".

One thing, hard to understand at the beginning, is that you can have multiple python instances installed on your machine. Anaconda is a great tool to manage the different "environments" having different python versions installed with different package combinations.

In your case Spyder uses a different interpreter as in your anaconda prompt, where you installed the package. Here, it is explained how to check, which Python interpreter is used by Spyder: https://stackoverflow.com/a/54237704/2196531

Mike S
  • 180
  • 1
  • 15