简体   繁体   中英

Can't install Python virtual environment for Python 3

I'm following these instructions on installing Python 3 with with Homebrew on my MacBook running Mac OSX High Sierra.

I'm having trouble with this step:

Once you've installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable. You can do this by adding the following line at the bottom of your ~/.profile file

export PATH=/usr/local/bin:/usr/local/sbin:$PATH

After updating ~/.profile and running python --version , I still see Python 2.7.10 .

This seems to be an issue because when I follow the next page to install a virtual environment using pip install --user pipenv , I get the following warning after installation completes:

The scripts pewtwo, pipenv and pipenv-resolver are installed in '/Users/charliesneath/Library/ Python/2.7 /bin' which is not on PATH.

It seems like my system is not properly prioritizing Homebrew's installation of Python 3.

How can I fix this?

For Mac, when you install python3, it is installed in a different path as those examples you are citing. To find out where the python3 is installed, type the command line:

which python3

It will return /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 .

Add the following lines to .bash_profile:

PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

I solved this once I eventually understood the following instructions :

If pipenv isn't available in your shell after installation, you'll need to add the user base's binary directory to your PATH .

On Linux and macOS you can find the user base binary directory by running python -m site --user-base and adding bin to the end. For example, this will typically print ~/.local (with ~ expanded to the absolute path to your home directory) so you'll need to add ~/.local/bin to your PATH . You can set your PATH permanently by modifying ~/.profile .

My system outputs /Users/charliesneath/Library/Python/3.6 when running the command, so I added the following to ~/.profile :

export PATH="~/Library/Python/3.6/bin"

Does anyone know why my system is not outputting ~/.local as suggested by the instructions above?


EDIT: It seems like version of Python I've installed is considered "framework build," and according to the Python documentation , the path I added to ~/.profile is the default "user base directory" for this framework:

site.USER_BASE : Default value is ~/.local for UNIX and Mac OS X non-framework builds, ~/Library/Python/XY for Mac framework builds, and %APPDATA%\\Python for Windows.

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