简体   繁体   中英

I am unable to install modules in Python on OSX

I am a beginner and am trying to install some modules in Python on OSX. I want to install SymPy.

One site says that I should run this in Terminal:

pip3 install SymPy

I ran it and I got this:

Aaryans-Macbook:~ apple$ pip3 install SymPy
Requirement already satisfied: SymPy in ./anaconda/lib/python3.6/site-packages (1.0)
Aaryans-Macbook:~ apple$

If I run Python in my Terminal and try importing SymPy, it works!

However, in my IDLE (where I write code), if I try to import it, I get this error:

import sympy
Traceback (most recent call last):
  File '<pyshell#0>', line 1, in <module>
    import sympy
ModuleNotFoundError: No module named 'sympy'

I have tried every sudo command in my Terminal but nothing worked.

I know this is very basic stuff but given the beginner, I am please, help me.

From your first screenshot, SymPy is installed using Anaconda, and in the second screenshot you are not running the IDLE that is included with Anaconda. Therefore it is not configured to locate the modules you installed.

On macOS, the full path may be /Users/jsmith/miniconda3/bin/idle3.5

(replace jsmith with your username)

You can confirm the different paths that Python is searching for by running this code:

import sys
sys.path

Execute those lines in both the Python you run from the command line, and the IDLE you run from the command line and you will see that they are different.

It is possible due to your path settings. See some examples of other peoples issues here How to add to the pythonpath in Windows?

Although the best thing is if when you install Python and select add Python to environment variables during the anaconda installation - but a quick workaround could be (specially for Mac)

http://osxdaily.com/2015/07/28/set-enviornment-variables-mac-os-x/

nano ~/ .bash_profile

then when your bash_profile opens, check your environment variables that you have

export PATH="/Users/username/anaconda3/bin:$PATH"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM