2018-12-22

python 常用管理命令

Anaconda 基本命令

conda -V : conda 版本

conda search "^python$" : conda 支持那些版本的 python

conda info : conda 的安裝設定訊息
conda list
conda list packagename

conda update conda
conda update anaconda
conda update --all

Anaconda 虛擬環境安裝及管理

conda create -n yourenvname python=x.x
conda create -p prefixpath_and_yourenvname python=x.x 改變 envs 所在位置
        ex : conda create --prefix=D:\python36\py36 python=3.6
activate yourenvname
(yourenvname) conda install packagename
(yourenvname) conda uninstall packagename
(yourenvname) deactivate
conda info -e
conda env remove -n yourenvname

以 pip 安裝及管理虛擬環境

pip install virtualenv
mkdir xxx
cd xxx
C:\Users\Cliff\AppData\Roaming\Python\Python311\Scripts\virtualenv yyy
"...\xxx\yyy\scripts\activate.bat"
(yyy) ...
deactivate
...

How to Upgrade All Pip Packages by pip

Here's a quick and easy way to upgrade all outdated pip/Python packages on a computer. It worked for me on Ubuntu 16.04, and looks like it will work on Mac and Windows too.

Save a list of Python packages to a file:

$ pip freeze > pip_frozen.txt

Then run this command (which might require sudo on some systems) -- it will upgrade every Python package listed in that file:

$ pip install -r pip_frozen.txt --upgrade

Another method :
The easiest way to update all packages in a Windows environment is to use pip in conjunction with Windows PowerShell: 

Open a command shell by typing ‘powershell’ in the Search Box of the Task bar
Enter:
pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_}
This will upgrade all packages system-wide to the latest version available in the Python Package Index (PyPI).

How do I upgrade the Python installation in Windows 10?

Every minor version of Python, that is any 3.x and 2.x version, will install side-by-side with other versions on your computer. Only patch versions will upgrade existing installations.

So if you want to keep your installed Python 2.7 around, then just let it and install a new version using the installer. If you want to get rid of Python 2.7, you can uninstall it before or after installing a newer version—there is no difference to this.

Current Python 3 installations come with the py.exe launcher, which by default is installed into the system directory. This makes it available from the PATH, so you can automatically run it from any shell just by using py instead of python as the command. This avoids you having to put the current Python installation into PATH yourself. That way, you can easily have multiple Python installations side-by-side without them interfering with each other. When running, just use py script.py instead of python script.py to use the launcher. You can also specify a version using for example py -3 or py -3.6 to launch a specific version, otherwise the launcher will use the current default (which will usually be the latest 3.x).

Using the launcher, you can also run Python 2 scripts (which are often syntax incompatible to Python 3), if you decide to keep your Python 2.7 installation. Just use py -2 script.py to launch a script.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.