Cannot get Python3 to recognize installed modules

Viewed 1405

I have scoured across StackOverflow and Google and have not been able to find a solution. I'm currently running the macOS Big Sur beta and I have Python 3.8.5 installed via homebrew. I have pip3 installed numpy and scrapy but anytime I try to import them I get:

AJs-MacBook-Pro:~ AJ$ cd PycharmProjects/Python/Projects/Web\ Scrape/
AJs-MacBook-Pro:Web Scrape AJ$ python3 scraper.py 
Traceback (most recent call last):
  File "scraper.py", line 1, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

As far as I know here is my only Python3 install:

AJs-MacBook-Pro:~ AJ$ which python3
/usr/local/bin/python3

Here is pip3:

AJs-MacBook-Pro:~ AJ$ which pip3
/usr/local/bin/pip3

My pip3 list:

AJs-MacBook-Pro:~ AJ$ pip3 list
Package          Version
---------------- -------
attrs            20.2.0
Automat          20.2.0
cffi             1.14.2
constantly       15.1.0
cryptography     3.1
cssselect        1.1.0
hyperlink        20.0.1
idna             2.10
incremental      17.5.0
itemadapter      0.1.0
itemloaders      1.0.3
jmespath         0.10.0
lxml             4.5.2
numpy            1.19.1
parsel           1.6.0
pip              20.1.1
Protego          0.1.16
pyasn1           0.4.8
pyasn1-modules   0.2.8
pycparser        2.20
PyDispatcher     2.0.5
PyHamcrest       2.0.2
pyOpenSSL        19.1.0
queuelib         1.5.0
Scrapy           2.3.0
service-identity 18.1.0
setuptools       50.3.0
six              1.15.0
Twisted          20.3.0
w3lib            1.22.0
wheel            0.34.2
zope.interface   5.1.0

I have nothing added in my bash profile. I am not sure where I am going wrong, any advice would be more than appreciated!

Edit: So I watched a tutorial on Youtube by Corey Schafer on how to setup a venv and that seems to fix my issue. Any modules downloaded into the venv are importable by Python with no issues. Thanks for the suggestions everyone!

3 Answers

Like other's have commented I recommend use a virtual env

$ python3 -m venv ~/web_scrape
$ source ~/web_scrape/bin/activate

python 3 venv

For troubleshooting:

find where numpy is installed

pip3 show numpy

Look for the Location: line

python 3 module search path

Go the my computer -open c drive -open users -open your pc named file

  • open app data -open program -open python -open scripts Then open cmd Code: pip install [module name]
Related