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 use the pyenv tool in Python

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use the pyenv tool in Python. It is very detailed and has a certain reference value. Friends who are interested must finish it!

1. Installation and configuration

Pyenv has been open source on github, and we clone the project directly from github to local:

Git clone https://github.com/pyenv/pyenv.git ~ / .pyenv

Then, execute the following command to install: then append the environment variables (path to pyenv, etc.) to the configuration file

Echo 'export PYENV_ROOT= "$HOME/.pyenv" > ~ / .profileecho' export PATH= "$PYENV_ROOT/bin:$PATH" > > ~ / .profileecho 'eval "$(pyenv init-- path)" > ~ > ~ / .profile

After installing and configuring the environment variables, you need to reload the configuration file to make the configuration just appended take effect. Generally use the source command, and the source command is usually used to re-execute the initialization file that has just been modified to make it take effect immediately without having to log out and log back in. As follows:

Source / .bash_profile

If there is no error at this point, the installation of pyenv is complete, and we can verify that pyenv is installed correctly and get help information for pyenv with the following command:

Pyenv-help

2. Use pyenv

We can see which Python versions are currently supported by pyenv through the install command of pyenv, as shown below:

Pyenv install-list

Note: the screenshot here is not complete, there are many versions.

You can use the pyenv versions command to view the version of Python included on the current system:

Pyenv versions

We haven't installed any other version of Python using pyenv here, so only one version of Python that comes with the system is used here.

You can use pyenv install to install different versions of Python:

Pyenv install 3.7.4pyenv install 3.8.0

There is a pit here. When you install Python using the pyenv install command, you will download the specified version from python.org by default. It will be very slow and will be stuck here all the time:

You can download the specified Python version from the domestic mirror website to the ~ / .pyenv / cache directory, and then install it with the pyenv install command, which will be quick. Taobao source is used here.

Wget https://npm.taobao.org/mirrors/python/3.7.4/Python-3.7.4.tar.xz-P ~ / .pyenv/cache

After downloading from a domestic source, when you execute the pyenv install command to install again, you will skip the download and install it directly.

After the installation is complete, running pyenv versions again will bring up the version of Python you just installed.

Because you just installed two Python versions, 3.7.4 and 3.8.0, plus the Python version that comes with the system, in which the'*'in front of the output indicates the version currently in use, so you can see that you are still using the Python version that comes with the system.

We can change the global Python version through pyenv global, as follows:

Pyenv global 3.7.4

If you do not want the specified Python version to take effect globally, but in the specified directory, you can use the pyenv local command to modify:

Pyenv local 3.7.4

This command only changes the Python environment in the directory where the naming is performed.

If you want to delete the Python version, use the uninstall command. As follows:

Pyenv uninstall 3.7.4 and above are all the contents of this article entitled "how to use pyenv tools in Python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report