2 versions of python on mac
- 2 versions of python on mac how to#
- 2 versions of python on mac mac os#
- 2 versions of python on mac install#
- 2 versions of python on mac Patch#
- 2 versions of python on mac upgrade#
python-version file in the current directory (if present). You can use the pyenv shell command to set this environment variable in your current shell session.
2 versions of python on mac install#
To install an additional version, say 3.4.0, simply use pyenv install 3.4.0. pyenv version shows this directly, and python -version can be used to verify this. Running pyenv versions will show which Python versions are currently installed, with a * next to the one currently in use. To do, open your in use shell script, via $ ~/.zshrc, $ ~/.bashrc or $ ~/.bash_profile and copy and paste the above line in. Next, add the following towards the bottom of your shell scripts to allow pyenv to automatically change versions for you: eval "$(pyenv init -)"
2 versions of python on mac mac os#
If using Mac OS X, we can do this using Homebrew, else consider other installation options.
2 versions of python on mac how to#
The pyenv documentation includes a great description of how it works, so here we will look simply at how to use it.įirstly we will need to install it. It does not come bundled with Python and must be installed separately. This is not to be confused with the previously mentioned depreciated pyvenv script. If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. If you do not need to use additional versions of Python itself, then this is all you need to create isolated, project specific, virtual environments. It will not be available when it is deactivated but will persist when it is reactivated. They will only exist in the virtual environment. This allows the shortcut command pip install -r requirements.txt command to quickly install all packages to the newly created virtual environment. Projects will commonly have a requirements.txt file specifying its dependencies.
2 versions of python on mac upgrade#
It is recommended to first upgrade pip to the latest version, using pip install -upgrade pip. As pip itself will not necessarily be installed on the machine. By default, the newly created environment will not include any packages already installed on the machine. When the environment is active, any packages can be installed to it via pip as normal.
2 versions of python on mac Patch#
However, any patch version (for example 3.6.4) will work. If the reader is using a version other than 3.6 then the command will not be successful and will indicate in its error message. If you are writing documentation, and want the additional safety that the correct version of Python is being used by your reader you can specify the major and minor version number in the command, like so: $ python3.6 -m venv example-three-six If you need to remove the environment completely after deactivating it, you can run: $ rm -r name-givenīy default, the environment it creates will be the current version of Python you are using. Venv is used to create a new environment via the terminal command: $ python3 -m venv directory-name-to-createĪctivated with: $ source name-given/bin/activateĪnd deactivated with simply: $ deactivate
For anyone interested you can read the reasons behind depreciating pyvenv. The exact same functionality is available when using venv, and any existing documentation should be updated. It will be completely removed in Python 3.8. Up until Python 3.6 a script called pyvenv was also included as a wrapper around venv, but this has been deprecated. It is ideal for creating lightweight virtual environments. venvįrom Python 3.3+ the venv package is included. If you also want to work with Python 2, then pyenv-virtualenv is a tool to consider. If you want to use multiple versions of Python at 3.3+, with or without virtual environments, then continue to read about pyenv.
If you are using a single version of Python say version 3.3+, and want to manage different virtual environments, then venv is all you need. Here we’ll look at three different tools for working with these, and when you might need each one.
Virtual environments: isolated independent environments that can have both a specific version of Python and of any project-specific packages installed within them, without affecting any other projects.Multiple Python versions: Different installations of Python on the same machine, 2.7 and 3.4 for example.Addition January 2019: If you are coming back to this blog after upgrading to macOS Mojave please see this github issue for a solution to the common pyenv ‘zlib not available’ problem.īefore we start, let’s briefly go over the terms used in the title: