Add to Python Path MAC Os X

Add to python path mac os x

Modifications to sys.path only apply for the life of that Python interpreter. If you want to do it permanently you need to modify the PYTHONPATH environment variable:

PYTHONPATH="/Me/Documents/mydir:$PYTHONPATH"
export PYTHONPATH

Note that PATH is the system path for executables, which is completely separate.

**You can write the above in ~/.bash_profile and the source it using source ~/.bash_profile

changing python path on mac?

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

This will append the Python directory to the path.

If this is part of ~/.bash_profile, this will append the Python path on each startup.

How can I edit PYTHONPATH on a Mac?

  1. You can append the path to $PATH and not to $PYTHONPATH.

  2. if you insist to change the PYTHONPATH, in some context that is
    prefferable:

    do this:

    export PYTHONPATH=$PYTHONPATH:/Users/username/pymodules
  3. To make sure you are following the convention of what to append to
    PYTHONPATH see
    What exactly should be set in PYTHONPATH?.

python location on mac osx

[GCC 4.2.1 (Apple Inc. build 5646)] is the version of GCC that the Python(s) were built with, not the version of Python itself. That information should be on the previous line. For example:

# Apple-supplied Python 2.6 in OS X 10.6
$ /usr/bin/python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

# python.org Python 2.7.2 (also built with newer gcc)
$ /usr/local/bin/python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Items in /usr/bin should always be or link to files supplied by Apple in OS X, unless someone has been ill-advisedly changing things there. To see exactly where the /usr/local/bin/python is linked to:

$ ls -l /usr/local/bin/python
lrwxr-xr-x 1 root wheel 68 Jul 5 10:05 /usr/local/bin/python@ -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python

In this case, that is typical for a python.org installed Python instance or it could be one built from source.

Make python3 as my default python on Mac

Probably the safest and easy way is to use brew and then just modify your PATH:

First update brew:

brew update

Next install python:

brew install python

That will install and symlink python3 to python, for more details do:

brew info python

Look for the Caveats:

==> Caveats
Python has been installed as
/usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin

Then add to your path /usr/local/opt/python/libexec/bin:

export PATH=/usr/local/opt/python/libexec/bin:$PATH

The order of the PATH is important, by putting first the /usr/local/opt/python/libexec/bin will help to give preference to the brew install (python3) than the one is in your system located in /usr/bin/python

How to manage Python path on MAC

Use pip3.x (e.g pip3.10) to install the package on the latest/currently used version of Python:

pip3.10 install django

or

python3.10 -m pip install django

And make sure the program is run by the same python executable

python3.10 manage.py makemigrations


Related Topics



Leave a reply



Submit