3

I am using Linux subsystem for Windows 10, in which several versions of Python have been installed. The default one, found by typing which python
in the shell is the one located in /opt/intel/oneapi/intelpython/latest/bin
, i.e. the default version of Intel OneAPI. I installed sympy by using the following command:

sudo apt-get install python3-sympy

and the corresponding folder seems to be located in /usr/bin/sympy . When I open Python, as I type import sympy, I get the message ModuleNotFoundError:No module named 'sympy'. Therefore, I would like to make the default version of Python recognize the 'sympy' package. Finally, I wish to thank for the collaboration in advance.

StellF
  • 33
  • 3

1 Answers1

2

APT installs python packages just into default system-wide Python installation.

To install python packages into your specific custom Python installation just do python -m pip install sympy, here python is your python's binary name or path, e.g. you can do /path/to/python -m pip install sympy.

You may need adding sudo to command to run it as root, i.e. sudo /path/to/python -m pip install sympy. Or another option is to install packages into user's directory by adding --user, i.e. /path/to/python -m pip install --user sympy. Both of these two options will work for you.

Notice! As said in @OscarBenjamin comment it is strongly not adviced to use sudo (better to use --user) because pip install can run any arbitrary code from Internet as root when used with sudo, see SO answers here. At least don't use sudo with untrusted pip packages.

Arty
  • 14,883
  • 6
  • 36
  • 69
  • Thank you very much, Arty. Now the package seems to be correctly recognized. I would like to inform you that, as I type the last command you suggested, I get the following warning: WARNING: The directory '/home/[username]/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. – StellF Apr 12 '21 at 12:34
  • @StellF Thanks for pointing that out! Just updated my answer, added information about usage of `sudo` or `--user` when doing pip install. In short just add `sudo` i.e. `sudo /path/to/python -m pip install sympy` or to install to user directory use `/path/to/python -m pip install --user sympy`, both variants will work. – Arty Apr 12 '21 at 12:55
  • 2
    You should not use sudo with pip https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip – Oscar Benjamin Apr 12 '21 at 13:54
  • @OscarBenjamin Thanks! Added your advice to my answer as **Notice!** – Arty Apr 12 '21 at 14:39