Previously I set up various machine learning libraries by the method of building a virtual environment introduced in the article, but as I investigated variously There is also code created in the python3 system operating environment, and it is troublesome to rewrite it for Python2 every time, so this time I would like to talk about introducing Python3 without breaking the default Python environment on the Mac.
--Reference: Procedure memo for creating a virtualenv environment with Homebrew Python2 and Python3
--Homebrew update
$ brew update
--Install virtualenv
$ pip install virtualenv
--Install Python3
brew install python3
$ mkdir -p $(Working directory name)
$ cd $(Working directory)
$ python3 -m venv venv
$ source venv/bin/activate
When I tried it, when I entered the command on the third line from the top, I got the following error.
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File
(Omission)
"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
When I looked it up, it seems that the PYTHON PATH I set earlier was in the way.
PYTHONPATH=/usr/local/lib/python2.7/site-packages
It seems that Python 3 didn't work because of this. (Reference) So, cancel the PYTHON_PATH setting with the following command.
$ unset PYTHONPATH
If you try again with this, you can build the environment without problems,
(venv)$
have become. Now you can run Python3. After that, you can use it by installing the libraries required in this environment from scratch. By the way, if you want to return to the original environment, just like last time
$ deactive
You can do it by typing.
Recommended Posts