简体   繁体   中英

Python cannot find package after pip install

I'm trying to install sumo using pip3 install --user sumo with Python@3.9 However although the sumo package is already installed, it cannot be invoked by which sumo , and same problem for which scipy & which numpy

In the site-package folder I can find all these packages, so it is definitely properly installed by pip3

Edited:

python3 -m site

sys.path = [
    '/Users/tonyspc',
    '/usr/local/lib/python3.9/site-packages',
    '/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
    '/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
    '/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
    '/Users/tonyspc/Library/Python/3.9/lib/python/site-packages',
    '/usr/local/Cellar/sip/6.1.1/libexec/lib/python3.9/site-packages',
    '/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages',
]
USER_BASE: '/Users/tonyspc/Library/Python/3.9' (exists)
USER_SITE: '/Users/tonyspc/Library/Python/3.9/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True

My current PATH for Python3 and pip3 is:

which python3 
/usr/local/opt/python@3.9/bin/python3

which pip3
/usr/local/opt/python@3.9/bin/pip3

I searched a little bit for solutions on the internet, none of them solved this issue.

1.I changed the environment variables for in the .bashrc and .bash_profile and sourced it

export PATH="/usr/local/opt/python@3.9/bin:$PATH"
export PYTHONPATH="/usr/local/lib/python3.9/site-packages/"

2.I changed file permission and attributes for site-packages folder

sudo chmod -R 755 /usr/local/lib/python3.9/site-packages/

3.I tried uninstall and reinstall Python@3.9 with Homebrew , still won't help

4.I tried uninstall and reinstall packages with pip3 install --user and Python3 -m pip install --user , still nothing changes.

Can anyone tell me the solution for this?

You cannot invoke a package that is not suposed to run as standalone in command shell.

To check if the package is correctly installed you can import inside Python

Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sumo

Otherwise you can run it in a shell calling the module with the "-m" parameter.

python3 -m <package> <parameters>

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