0

I'm relatively new to coding, this is my first Stack Overflow question! I recently installed PyPy. It works fine if the code I'm running doesn't import much. But when my code tries to import, e.g., NumPy, I get: "ModuleNotFoundError: No module named 'numpy'." Same with other major packages; though it seems to import Itertools. I know I have all these packages somewhere, because they work when I run the code through Jupyter, etc. Googling around it seems like PyPy should support all the major packages, so I assume I need to link them up somehow...? Any advice or links to resources much appreciated!

MacOS 10.15.1

$ pypy3 --version
Python 3.6.9 (5da45ced70e515f94686be0df47c59abd1348ebc, Nov 22 2019, 03:55:25)
[PyPy 7.2.0 with GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.12)]
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

2 Answers2

1

How did you install the packages? Did you do pip install or pypy3 -mpip install? The latter is what you should use if you have more than one Python installed so that they are installed for your desired Python and not the system default.

Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • Thanks! I'm very new to this, sorry for my boneheadednessm really appreciate your help. I installed Anaconda to begin with, and have since pip installed a few things. I checked a few, and looks like they all live in the same place: /Applications/anaconda3/lib/python3.7/site-packages – Dan Brendel Dec 06 '19 at 23:03
  • I did what Nate below said and added the following to .zprofile PYTHONPATH="/Applications/anaconda3/lib/python3.7/site-packages:$PYTHONPATH" export PYTHONPATH Now it appears to know where to look, but I think PyPy is not compatible with the latest Python version I have located here. Now I get a new ImportError: Check that you expected to use Python3.6 from "/usr/local/bin/pypy3", and that you have no directories in your PATH or PYTHONPATH that can interfere with the Python and numpy version "1.17.4" you're trying to use. – Dan Brendel Dec 06 '19 at 23:31
0

try use same python executable with jupyter.

import sys
print(sys.executable)

or install packages with pip install numpy

if you can find the install location for your package with somthing like

import numpy
print(numpy.__file__)

add the site-package folder to PYTHONPATH environment variable should work for you.

see How to use PYTHONPATH

Nate Scarlet
  • 551
  • 5
  • 7
  • Thank you very much for this! I added to PYTHONPATH successfully, but got a new error, perhaps because pypy3 isn't compatible with the latest pypi packages...? Reading through some documentation, I think maybe I need to install a virtual environment and run pypy3 out of that...? Does that sound reasonable, any idea of good references to walk through how to do that? Thank you! – Dan Brendel Dec 07 '19 at 00:25
  • @dan-brendel i never used anaconda and pypy, but i guess you are not running the [anaconda python executable](https://docs.anaconda.com/anaconda/user-guide/tasks/integration/python-path/)? – Nate Scarlet Dec 07 '19 at 01:25