简体   繁体   English

Python:如何在 pyenv-virtual-environment 中更新 python 版本?

[英]Python: How can I update python version in pyenv-virtual-environment?

I used pyenv , pyenv-virtualenv for managing python virtual environment.我使用pyenvpyenv-virtualenv来管理 python 虚拟环境。

I have a project working in Python 3.4 virtual environment.我有一个在Python 3.4虚拟环境中工作的项目。

So all installed packages( pandas , numpy etc) are not newest version.所以所有安装的包( pandasnumpy等)都不是最新版本。

What I want to do is to upgrade Python version from 3.4 to 3.6 as well as upgrade other package version to higher one.我想要做的是将Python版本从 3.4 升级到 3.6 以及将其他包版本升级到更高版本。

How can I do this easily?我怎样才能轻松做到这一点?

Here is how I switched to 3.9.0 :这是我切换到3.9.0的方式:

$ pip freeze > requirements-lock.txt
$ pyenv virtualenv-delete a-virtualenv-name
$ pyenv virtualenv 3.9.0 a-virtualenv-name
$ pip install -r requirements-lock.txt
$ rm requirements-lock.txt

Using pip freeze > requirements.txt is usually not a good idea as this file is often used to handle your package requirements ( not necessarily pip freeze output).使用pip freeze > requirements.txt通常不是一个好主意,因为该文件通常用于处理您的包要求(不一定是pip freeze输出)。 It's better to use a different (temporary) file just to be sure.为了确定,最好使用不同的(临时)文件。

Use pip freeze > requirements.txt to save a list of installed packages.使用pip freeze > requirements.txt保存已安装包的列表。

Create a new venv with python 3.6.使用 python 3.6 创建一个新的 venv。

Install saved packages with pip install -r requirements.txt .使用pip install -r requirements.txt安装保存的包。 When pip founds an universal wheel in its cache it installs the package from the cache.当 pip 在其缓存中找到一个通用轮子时,它会从缓存中安装包。 Other packages will be downloaded, cached, built and installed.其他包将被下载、缓存、构建和安装。

If you use anaconda, just type如果你使用 anaconda,只需输入

conda install python==$pythonversion$康达安装 python==$pythonversion$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM