Python 2, 3 site-package path management.

Asked 2 years ago, Updated 2 years ago, 113 views

In an OSX environment, you are using python2, python3.

I usually use python2, but I often use python3 for tensorflow, jupyter notebook, etc

After updating with brew, I was able to confirm that the site-package path installed through pip and pip3 has changed.

Therefore, the problem that is occurring now is that libraries installed through pip from terminal are normally imported from Python2 and Python3 environments running in terminal environments, but when running in other environments such as jupyter, getsitepackage() does not contain a path.

Of course, I know that declaring sys.path.append and adding a path will make it a normal use, but there is always the hassle of declaring it.

It's the same problem as the article below

http://hashcode.co.kr/questions/1184/pythonpath%EC%97%90-%EC%98%81%EA%B5%AC%EC%A0%81%EC%9C%BC%EB%A1%9C-%EB%94%94%EB%A0%89%ED%86%A0%EB%A6%AC-%EC%B6%94%EA%B0%80%ED%95%98%EA%B8%B0

in the above article, presented export PYTHONPATH="${PYTHONPATH}:/my/other/path" It seemed to be resolved temporarily using the , but since I do not use the virtual env environment, when adding environment variables as above, when executing python2 and python3 respectively, the following errors were found.

Failed to import the site module
Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"
     You should `unset PYTHONPATH` to fix this.

We were able to restore it again with the following settings.

unset PYTHONPATH

The question I want to ask is,

import site
site.getsitepackages()

I would like to know how to add some missing paths to the site-package path that is loaded when you do the .

I think if you add only the missing site-package path, it will be used normally, but even if I search for it, I could only find the same kind of answer as above, so I couldn't solve it.

I would appreciate it if you could tell me a solution to the above problem!

python2.7 python3.6.3 site-package

2022-09-22 18:51

1 Answers

Usually, that's why you use tools to create virtual contexts, such as virtualenv or venv.

Create a separate (dedicated) environment with virtualenv, venv-like tools.


2022-09-22 18:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.