Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install pyenv in mac

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to install pyenv in mac. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

1. Install brew

Ruby-e "$(curl-fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install](https://raw.githubusercontent.com/Homebrew/install/master/install))"

It's very slow to install this. So do what you have to do first.

two。 Install pyenv

Brew install pyenv

Edit ~ / .bash_profile after installation

Export PYENV_ROOT=/usr/local/var/pyenvif which pyenv > / dev/null; then eval "$(pyenv init -)"; fi

Remember source ~ / .bash_profile after installation is complete.

3. Install the zlib dependency package

Brew install zlib

Establish a soft connection after installation

Ln-s / usr/local/Cellar/zlib/1.2.8/include/* / usr/local/includeln-s / usr/local/Cellar/zlib/1.2.8/lib/* / usr/local/lib

4. Use pyenv

First of all, let's take a look at what the pyenv commands are.

$pyenv-helpUsage: pyenv [] Some useful pyenv commands are: commands List all available pyenv commands local Set or show the local application-specific Python version global Set or show the global Python version shell Set or show the shell-specific Python version install Install a Python version using python-build uninstall Uninstall a specific Python version rehash Rehash pyenv shims (run this after installing executables) version Show the current Python version and its origin versions List all Python versions available to pyenv Which Display the full path to an executable whence List all Python versions that contain the given executableSee pyenv help 'for information on a specific command.For full documentation See: https://github.com/pyenv/pyenv#readme`

Use the command to view the installable version of py

Pyenv install-- listAvailable versions:2.1.32.2.32.3.72.4.02.4.1...

Then select the desired version to install

Pyenv install-v 3.6.4

View the version after installation

Pyenv versions* system (set by / usr/local/var/pyenv/version) 3.6.4

The one with a * sign indicates the version currently in use. We can switch the version with the command.

Pyenv global 3.6.4$ pythonPython 3.6.4 (default, Jul 4 2019, 09:57:03) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwinType "help", "copyright", "credits" or "license" for more information. > > $pyenv versions system* 3.6.4 (set by / usr/local/var/pyenv/version)

5. Install pyenv-virtualenv isolated work environment

First of all, talk about the difference between pyenv and virtualenv. Pyenv manages the python version, and you can use pyenv to achieve simultaneous existence using more python versions. And virtualenv is the key to diversifying our project environment. Each project can use a different third-party library. All right, now that we know the difference, let's look at how to install and use it.

Brew install pyenv-virtualenv

After installation, edit ~ / .bash_profile to add the following command

If which pyenv-virtualenv-init > / dev/null; then eval "$(pyenv virtualenv-init -)"; fi

Remember source ~ / .bash_profile after you finish it.

First, let's create a work environment. Multiple work environments can be created with the same and different versions of Python

Pyenv virtualenv 3.6.4 first_project$ pyenv virtualenvs 3.6.4/envs/first_project (created from / usr/local/var/pyenv/versions/3.6.4) first_project (created from / usr/local/var/pyenv/versions/3.6.4)

After the creation is completed, we can enter the work environment.

Pyenv activate first_project (first_project) $pip install flask

Third-party libraries can then be installed at will, and each work environment does not affect each other, such as installing flask 1.0 in A work environment. Then install 1.1 in B, which is fine.

You can exit the current work environment using the following command

Pyenv deactivate after reading the above, do you have any further understanding of how to install pyenv in mac? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report