阿里云Ubuntu服務(wù)器通過Anaconda配置python純凈虛擬環(huán)境

由于阿里云的ubuntu服務(wù)器 默認(rèn)有一個(gè)2.7一個(gè)3.5版本的python,如果又另外安裝和使用更高版本的話挂据,經(jīng)常會(huì)遇到運(yùn)行python程序出現(xiàn)已經(jīng)安裝依賴包但找不到對(duì)應(yīng)依賴包的情況滨彻。

給遠(yuǎn)程服務(wù)器安裝Anaconda蚪黑,然后用conda創(chuàng)建新的python虛擬環(huán)境丁侄,并且可以根據(jù)生產(chǎn)需求切換不同的python版本棋凳。

1、Anaconda下載安裝:

下載地址1:Anaconda官網(wǎng)
下載地址2:清華源地址
下載所需的Anaconda 版本至自己的服務(wù)器(隨便選一個(gè)自己的文件放就行)坠陈。

qiang@09230:~$ cd /home/qiang
qiang@09230:~$ wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
--2022-05-09 20:02:26--  https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
Resolving repo.anaconda.com (repo.anaconda.com)... 104.16.131.3, 104.16.130.3, 2606:4700::6810:8303, ...
Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.131.3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 570853747 (544M) [application/x-sh]
Saving to: ‘Anaconda3-2021.05-Linux-x86_64.sh’

Anaconda3-2021.05-Linux-x86_64.sh                     100%[========================>] 544.41M  11.8MB/s    in 1m 51s

2022-05-09 20:04:18 (4.91 MB/s) - ‘Anaconda3-2021.05-Linux-x86_64.sh’ saved [570853747/570853747]

qiang@09230:~$ ls
Anaconda3-2021.05-Linux-x86_64.sh  
qiang@09230:~$

在Linux系統(tǒng)里面.sh文件是可執(zhí)行的腳本文件萨惑,可以用命令bash來進(jìn)行安裝。
在安裝包文件目錄下輸入安裝命令:

bash Anaconda3-2019.10-Linux-x86_64.sh
qiang@09230:~$ ls
 AlarmReport.log                     BoxCommunicationRun.log   flask                     'Lif tControlTest.txt'   MQTT            mysql_bak.sh               protect.sh        wget-log.1
 anaconda3                           django.log                flask.log                  LiftControlTest.txt     mqtt.log        NaviCommunicationRun.log   qiang             yangrui
 Anaconda3-2021.05-Linux-x86_64.sh   django_projects           LiftCommunicationRun.log   log                     mysql_bak2.sh   nginx-auth-ldap            start_server.sh
 BackGarden                          element.log               LiftControlNode.log        mapbackup               mysql_bak3.sh   nohup.out                  test
 bak                                 FlashCommunication.log    LiftControlTest.log        mapsync                 mysql_bak4.sh   php                        wget-log
qiang@09230:~$ sudo bash Anaconda3-2021.05-Linux-x86_64.sh

Welcome to Anaconda3 2021.05

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
===================================
End User License Agreement - Anaconda Individual Edition
===================================

Copyright 2015-2021, Anaconda, Inc.

All rights reserved under the 3-clause BSD License:

This End User License Agreement (the "Agreement") is a legal agreement between you and Anaconda, Inc. ("Anaconda") and governs your use of Anaconda Individual Edition (which was formerly known as Anaconda Distributi
on).

Subject to the terms of this Agreement, Anaconda hereby grants you a non-exclusive, non-transferable license to:
...........................
Export; Cryptography Notice
===========================

You must comply with all domestic and international export laws and regulations that apply to the software, which include restrictions on destinations, end users, and end use. Anaconda Individual Edition includes cr
yptographic software. The country in which you currently reside may have restrictions on the import, possession, use, and/or re-export to another country, of encryption software. BEFORE using any encryption software
, please check your country's laws, regulations and policies concerning the import, possession, or use, and re-export of encryption software, to see if this is permitted. See the Wassenaar Arrangement http://www.was
senaar.org/ for more information.

Anaconda has self-classified this software as Export Commodity Control Number (ECCN) 5D992.c, which includes mass market information security software using or performing cryptographic functions with asymmetric algo
rithms. No license is required for export of this software to non-embargoed countries.

The Intel Math Kernel Library contained in Anaconda Individual Edition is classified by Intel as ECCN 5D992.c with no license required for export to non-embargoed countries.

The following packages listed on https://www.anaconda.com/cryptography are included in the repository accessible through Anaconda Individual Edition that relate to cryptography.

Last updated April 5, 2021

Do you accept the license terms? [yes|no]
[no] >>> yes

Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/anaconda3] >>> yes
......................................
 ujson              pkgs/main/linux-64::ujson-4.0.2-py38h2531618_0
  unicodecsv         pkgs/main/linux-64::unicodecsv-0.14.1-py38_0
  unixodbc           pkgs/main/linux-64::unixodbc-2.3.9-h7b6447c_0
  urllib3            pkgs/main/noarch::urllib3-1.26.4-pyhd3eb1b0_0
  watchdog           pkgs/main/linux-64::watchdog-1.0.2-py38h06a4308_1
  wcwidth            pkgs/main/noarch::wcwidth-0.2.5-py_0
  webencodings       pkgs/main/linux-64::webencodings-0.5.1-py38_1
  werkzeug           pkgs/main/noarch::werkzeug-1.0.1-pyhd3eb1b0_0
  wheel              pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0
  widgetsnbextension pkgs/main/linux-64::widgetsnbextension-3.5.1-py38_0
  wrapt              pkgs/main/linux-64::wrapt-1.12.1-py38h7b6447c_1
  wurlitzer          pkgs/main/linux-64::wurlitzer-2.1.0-py38h06a4308_0
  xlrd               pkgs/main/noarch::xlrd-2.0.1-pyhd3eb1b0_0
  xlsxwriter         pkgs/main/noarch::xlsxwriter-1.3.8-pyhd3eb1b0_0
  xlwt               pkgs/main/linux-64::xlwt-1.3.0-py38_0
  xmltodict          pkgs/main/noarch::xmltodict-0.12.0-py_0
  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
  yaml               pkgs/main/linux-64::yaml-0.2.5-h7b6447c_0
  yapf               pkgs/main/noarch::yapf-0.31.0-pyhd3eb1b0_0
  zeromq             pkgs/main/linux-64::zeromq-4.3.4-h2531618_0
  zict               pkgs/main/noarch::zict-2.0.0-pyhd3eb1b0_0
  zipp               pkgs/main/noarch::zipp-3.4.1-pyhd3eb1b0_0
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
  zope               pkgs/main/linux-64::zope-1.0-py38_1
  zope.event         pkgs/main/linux-64::zope.event-4.5.0-py38_0
  zope.interface     pkgs/main/linux-64::zope.interface-5.3.0-py38h27cfd23_0
  zstd               pkgs/main/linux-64::zstd-1.4.5-h9ceee32_0


Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>>yes
......................................
no change     /home/qiang/yes/lib/python3.8/site-packages/xontrib/conda.xsh
no change     /home/qiang/yes/etc/profile.d/conda.csh
modified      /root/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

If you'd prefer that conda's base environment not be activated on startup,
   set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Anaconda3!

===========================================================================

Working with Python and Jupyter notebooks is a breeze with PyCharm Pro,
designed to be used with Anaconda. Download now and have the best data
tools at your fingertips.

PyCharm Pro for Anaconda is available at: https://www.anaconda.com/pycharm

qiang@09230:~$

一直按Enter回車鍵繼續(xù)仇矾,接受許可條款庸蔼。注意按enter別安太快,接下來會(huì)提示是否添加環(huán)境變量贮匕,輸入yes姐仅,否則還得自己配環(huán)境變量。

輸入 python 命令進(jìn)入python環(huán)境,同時(shí)終端的頭部會(huì)出現(xiàn)(base),說明Anaconda已經(jīng)安裝成功了掏膏,接下來可以創(chuàng)建純凈python編譯環(huán)境了劳翰。

(base) qiang@09230:~$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

另外如果需要每次打開服務(wù)器終端時(shí)自動(dòng)激活conda的base環(huán)境,可以輸入如下命令:

conda config --set auto_activate_base false

2、使用conda創(chuàng)建新的python環(huán)境

conda create --name qiang python=3.8.10
qiang@09230:~$ source ~/.bashrc
(base) qiang@09230:~$ conda config --set auto_activate_base false
(base) qiang@09230:~$ conda config --set auto_activate_base true
(base) qiang@09230:~$ conda create --name qiang python=3.8.10
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.10.1
  latest version: 4.12.0

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /home/qiang/tools/anaconda3/envs/qiang

  added / updated specs:
    - python=3.8.10


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    python-3.8.10              |       h12debd9_8        57.7 MB
    ------------------------------------------------------------
                                           Total:        57.7 MB

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-4.5-1_gnu
  ca-certificates    pkgs/main/linux-64::ca-certificates-2022.4.26-h06a4308_0
  certifi            pkgs/main/linux-64::certifi-2021.10.8-py38h06a4308_2
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.35.1-h7274673_9
  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_2
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.3.0-h5101ec6_17
  libgomp            pkgs/main/linux-64::libgomp-9.3.0-h5101ec6_17
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.3.0-hd4cf53a_17
  ncurses            pkgs/main/linux-64::ncurses-6.3-h7f8727e_2
  openssl            pkgs/main/linux-64::openssl-1.1.1o-h7f8727e_0
  pip                pkgs/main/linux-64::pip-21.2.4-py38h06a4308_0
  python             pkgs/main/linux-64::python-3.8.10-h12debd9_8
  readline           pkgs/main/linux-64::readline-8.1.2-h7f8727e_1
  setuptools         pkgs/main/linux-64::setuptools-61.2.0-py38h06a4308_0
  sqlite             pkgs/main/linux-64::sqlite-3.38.3-hc218d9a_0
  tk                 pkgs/main/linux-64::tk-8.6.11-h1ccaba5_1
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  xz                 pkgs/main/linux-64::xz-5.2.5-h7f8727e_1
  zlib               pkgs/main/linux-64::zlib-1.2.12-h7f8727e_2


Proceed ([y]/n)? y


Downloading and Extracting Packages
python-3.8.10        | 57.7 MB   | ############################################################################################################################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate qiang
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) qiang@09230:~$ conda active qiang

CommandNotFoundError: No command 'conda active'.
Did you mean 'conda activate'?

(base) qiang@09230:~$ conda activate qiang
(qiang) qiang@09230:~$

這時(shí)在終端輸入python馒疹,就可以看到我們剛剛建立好的環(huán)境:

(qiang) qiang@09230:~$ python
Python 3.8.10 (default, Jun  4 2021, 15:09:15)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(qiang) qiang@09230:~$

3佳簸、激活環(huán)境
激活之前先查看環(huán)境

(qiang) qiang@09230:~$ conda env list
# conda environments:
#
yourEnv                  /home/qiang/.conda/envs/yourEnv
base                     /home/qiang/tools/anaconda3
qiang                 *  /home/qiang/tools/anaconda3/envs/qiang

(qiang) qiang@09230:~$

激活環(huán)境:

(qiang) qiang@09230:~$ source activate base
(base) qiang@09230:~$ 

常用命令:

source activate yourEnv  # 激活環(huán)境
source deactivate yourEnv  # 退出環(huán)境
conda env remove -n yourEnv  # 刪除環(huán)境  
conda remove --name xxxx  --all #徹底刪除舊環(huán)境
conda remove -n yourEnv package_name  # 刪除環(huán)境中的某個(gè)包

如果你手動(dòng)修改過配置環(huán)境,需要執(zhí)行下面命令颖变,使用source命令執(zhí)行腳本/.bashrc(/.bashrc會(huì)調(diào)用 /etc/bashrc文件)
source ~/.bashrc

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末生均,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子悼做,更是在濱河造成了極大的恐慌疯特,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,123評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件肛走,死亡現(xiàn)場(chǎng)離奇詭異漓雅,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)朽色,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,031評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門邻吞,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人葫男,你說我怎么就攤上這事抱冷。” “怎么了梢褐?”我有些...
    開封第一講書人閱讀 156,723評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵旺遮,是天一觀的道長。 經(jīng)常有香客問我盈咳,道長耿眉,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,357評(píng)論 1 283
  • 正文 為了忘掉前任鱼响,我火速辦了婚禮鸣剪,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘丈积。我一直安慰自己筐骇,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,412評(píng)論 5 384
  • 文/花漫 我一把揭開白布江滨。 她就那樣靜靜地躺著铛纬,像睡著了一般。 火紅的嫁衣襯著肌膚如雪唬滑。 梳的紋絲不亂的頭發(fā)上告唆,一...
    開封第一講書人閱讀 49,760評(píng)論 1 289
  • 那天莫秆,我揣著相機(jī)與錄音,去河邊找鬼悔详。 笑死,一個(gè)胖子當(dāng)著我的面吹牛惹挟,可吹牛的內(nèi)容都是我干的茄螃。 我是一名探鬼主播,決...
    沈念sama閱讀 38,904評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼连锯,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼归苍!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起运怖,我...
    開封第一講書人閱讀 37,672評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤拼弃,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后摇展,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吻氧,經(jīng)...
    沈念sama閱讀 44,118評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,456評(píng)論 2 325
  • 正文 我和宋清朗相戀三年咏连,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了盯孙。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,599評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡祟滴,死狀恐怖振惰,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情垄懂,我是刑警寧澤骑晶,帶...
    沈念sama閱讀 34,264評(píng)論 4 328
  • 正文 年R本政府宣布,位于F島的核電站草慧,受9級(jí)特大地震影響桶蛔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜冠蒋,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,857評(píng)論 3 312
  • 文/蒙蒙 一羽圃、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧抖剿,春花似錦朽寞、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,731評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至缩宜,卻和暖如春肘迎,著一層夾襖步出監(jiān)牢的瞬間甥温,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,956評(píng)論 1 264
  • 我被黑心中介騙來泰國打工妓布, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留姻蚓,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,286評(píng)論 2 360
  • 正文 我出身青樓匣沼,卻偏偏與公主長得像狰挡,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子释涛,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,465評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容