程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Full solution of Ubuntu maintenance 7 CONDA environment_ python_ jupyter

編輯:Python

Suggest :
Whether it's win10 System or Ubuntu System ,
If you want to use python, Directly in Ubuntu Installation on miniconda,
establish conda Environment for use
( The scheme is the most concise , Safest , The most perfect python Idea of creating running environment )

  • install Ubuntu after , Never mind what comes with the system Python, Because the version is difficult to control

  • Download and install directly anconda wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh

  • Configure the update after installation conda Download source and pip Update to the latest , Then create the environment , Or use the default conda user

  • At this moment in the system Python In theory, it's all conda Of course.

  • Then create python The environment began to use , It is emphasized that it is not recommended to change the local python and conda Bring their own python

  • It is not recommended to change the local python and conda Bring their own python

  • It is not recommended to change the local python and conda Bring their own python

  • It is not recommended to change the local python and conda Bring their own python

2020/11/17 to update :
Today because of hanging up V7N, Directly lead to network error , Creating conda Error in environment , Then deleted according to the logic on the Internet ~/.condarc, Lead to the whole conda crash , Had to reinstall
This is an installation miniconda Some details are clearly written in the tutorial

List of articles

  • One . conda
    • 1.1 Introduce conda
    • 1.2 conda Download and install , It is recommended to execute all the following commands
    • 1.3 conda Use
    • 1.4 Problems in creating the environment
  • Two . System native Python, Not recommended
    • 2.1 Download and install Modify download source
    • 2.2 pip and pip3 The difference between
    • 2.3 Set up Ubuntu The default startup is python3
  • 3、 ... and . pycharm
    • 3.0 pycharm pro 2021
    • 3.1 pycharm python Compiler download and installation
    • 3.2 Build soft links ,pycharm install
  • 3.4 win10 install pycharm The education version uses the subsystem Ubuntu Of conda Environment
    • a. Go to pycharm Register the education version on the official website
    • b. When choosing the environment , choice Ubuntu in conda The environment is also very simple
    • c. utilize pycharm Is that
    • d. pycharm Link remote server ssh-SFTP
      • pycharm Start a terminal Connect ssh
      • pycharm add to ssh
      • pycharm Connect ssh
      • Create project
  • Four . anconda With the local python Conflict resolution
  • 5、 ... and . `jupyter notebook`
    • 5.1 jupyter stay conda Use in the environment
    • 5.2 jupyter Login password settings
    • 5.3 jupyter Common shortcut key
  • 6、 ... and . The old Ubuntu install Python3.6
  • 7、 ... and . python Package management
  • Problem summary
    • a. jupyter Unable to complete

This article mainly introduces from two aspects python

conda and python Icon

One . conda

1.1 Introduce conda

  • conda It's a python Version and environment management tools
  • Can pass conda Create a new python Environmental Science , And the newly created python In the environment python There is no conflict between the version and the package

1.2 conda Download and install , It is recommended to execute all the following commands


The first part is to install the full version conda, Large software , her beauty is good enough for the aristocracy

It is recommended to use the second method to install mini Version of conda

wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
chmod 777 anaconda*.sh # Convert to executable 
sudo ./anaconda*.sh # install Pay attention The first one here yes Don't press enter after that 
Do you wish the installer to initialize Anaconda3
in your /home/user1/.bashrc ? [yes|no]
[no] >>> yes
# Be careful :: Be careful 
# Don't press enter here , Because you will be asked whether to install to the local environment variable , If you press enter, the default is not to add local variables , It would be embarrassing , 
# Also note that this is not only added to the local environment variable , You still need to perform the following source ~/.bashrc, The system can only recognize conda
Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
>>> no
# The installation has been completed here , 
# But in this case conda It's not working yet , Why? , Because although it is installed, it will conda Environment variables are added to the system , However, the system environment variable has not yet taken effect ; Therefore, you need to run the following command to take effect 
source ~/.bashrc
# If you do not choose to directly add environment variables during installation , Please run the following command 
echo 'export PATH="/home/user01/anaconda/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# Set up conda Download source , This will reduce the error probability when creating a new user 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ # This is the download source of Tsinghua University 
conda config --set show_channel_urls yes # Set the search display address 
# to update pip
pip install --upgrade pip # If this error is reported, execute the following commands 
pip install --upgrade pip --user
# Set up pip Default download source 
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# Or you can do it alone at a time pip When downloading the package, make the download source 
pip install numpy==1.14.0 -i https://mirrors.aliyun.com/pypi/simple/

The second part is to install the mini version conda, Software 100M, smaller , Still young

wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod 777 Miniconda3-latest-Linux-x86_64.sh # Give Execution Authority 
./Miniconda3-l*
yes # Determine the installation regulations 
yes # Confirm will conda Add to the system 
source ~/.bashrc # Activate 
# The following four are download sources 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes # According to the path 
conda config --get channels # View channels 
cat ~/.condarc # see The added path is saved in 

1.3 conda Use

# conda Some operations of the environment 
conda create -n mypy python=3.6 # Create the name as mypy Environment 
conda env list # Displays a list of environments 
source activate mypy # Enter the environment 
source deactivate # Out of the environment 
conda create -n mypy_new --clone mypy # clone mypy Environmental Science 
conda env export > freeze.yml # pack mypy Environmental Science 
conda create -n mypy -f freeze.yml
conda remove -n mypy --all # Delete mypy Environmental Science 

1.4 Problems in creating the environment

Check the network first

  • remove mv ~/.condarc ~/.condarc_old
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --set show_channel_urls yes # According to the path 
conda config --get channels # View channels 

At this point, the new generation ~/.condarc
conda install jupyter There will still be mistakes
Then try conda install -c conda-forge jupyter

Two . System native Python, Not recommended

2.1 Download and install Modify download source

sudo apt install python3-pip # install python3
pip3 install pip # Python3 Bring their own pip3, install pip
-i https://pypi.tuna.tsinghua.edu.cn/simple # Can be in pip Later, it is used to modify the download source 
sudo apt install python-pip # install pip
# Modify the download source for permanent use 
pip install pip -U
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# Other sources 
Alibaba cloud http://mirrors.aliyun.com/pypi/simple/
University of science and technology of China https://pypi.mirrors.ustc.edu.cn/simple/
douban (douban) http://pypi.douban.com/simple/
Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/
University of science and technology of China http://pypi.mirrors.ustc.edu.cn/simple/

2.2 pip and pip3 The difference between

from pip in pip and pip3 The difference between

  • pip yes python Package management tools ,pip and pip3 Different versions , All in Scripts\ Under the table of contents :
  • If only Python2, Then you can only use pip.
  • If only Python3, So you can use pip You can also use pip3, The two are equivalent .
  • If the system is installed with Python2 and Python3, be pip By default Python2 use ,pip3 Assign to Python3 use .
  • important : In a virtual environment , If there is only one python edition , It can be considered that in the system in use pip and pip3 The commands are the same

2.3 Set up Ubuntu The default startup is python3

[email protected]:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
[sudo] zjq Password :
update-alternatives: Use /usr/bin/python3 To provide... In automatic mode /usr/bin/python (python)

update-alternatives Introduce
update-alternatives You can create 、 Delete 、 Repair 、 Soft connection , It can also display the information of existing soft connection , And all these constitute the alternative system (alternatives system).
update-alternatives Is a symbolic link used to maintain system commands , To determine what commands the system uses by default , You can set the preferred program loaded by default
For example, my system has been installed with java 1.6, I also want to install java 1.7, But I don't want to uninstall java 1.6. You can go through update-alternatives --config In more than one java Inter version process switching .update-alternatives It is a command used to switch among multiple commands of the same type .

3、 ... and . pycharm

3.0 pycharm pro 2021

Download and install on the official website , Give the following to jar Drag files to pycharm On the main page

Infinite loop trial 30 God



At this point, you can use it indefinitely

3.1 pycharm python Compiler download and installation

Community version download link
Left black Download Community version , It can be used directly without activation

After the download is completed, the compressed package , Unzip to ~ Under the table of contents
$ tar -zvxf pycharm-community-2020.1.tar.gz -C ~
mv pycharm pyc # This is for convenience next time
$ sh ~/pyc/bin/pycharm.sh # Open software pycharm
You can use the local Python, Open the project
file->setting-> Select local project
Open the project , Set up conda Path and , choice RGIN user

3.2 Build soft links ,pycharm install

Such as my pycharm Each time you need to use the command to open

[email protected]:~$ sh ~/pyc/bin/pycharm.sh

Because lazy, so opportunistic , Establish the following soft connection
Note that it must be from ~…pycharm Set up to ----> /usr…pycharm
[email protected]:~$ sudo ln -s ~/pyc/bin/pycharm.sh /usr/bin/pycharm
The above command means :
stay /usr/bin/pycharm Create a new directory pycharm Open shortcut
If you need to run pycharm, Just type... On the command line
pycharm.sh You can directly open pycharm Software

* It should be noted that : *

  • /usr/bin/ All stored in the directory are executable files , Will be able to sh, Put binary files in this directory , The global can be executed without positioning
  • ln -s Create a soft link , If you want to delete , You can find the soft connection to delete ,
    If this soft link is deleted sudo rm /usr/bin/pycharm

3.4 win10 install pycharm The education version uses the subsystem Ubuntu Of conda Environment

a. Go to pycharm Register the education version on the official website

You need to use the school mailbox , Never think of a bunch of dirt B, Use the code tool to 99 year , Just borrow an account from a little brother who is still in school around you ;
Directly follow the prompts on the official website to download, install and log in to the school email for verification

b. When choosing the environment , choice Ubuntu in conda The environment is also very simple

c. utilize pycharm Is that

can debug, Be able to see the contents of everyone's variables at each step , Format

d. pycharm Link remote server ssh-SFTP

pycharm Start a terminal Connect ssh

pycharm add to ssh

pycharm Connect ssh

Create project

Four . anconda With the local python Conflict resolution

  • Be careful : Local... Is not recommended python, Installation is recommended Ubuntu First install anconda, Then the default system is conda The environment

Python3 Turn into anaconda Medium Python Why : install anaconda After that, the inside Python3 Adding to the environment variable overwrites the original Python3 edition
Use alias to declare alias Order to change
The following command is to set the local python Connect as python, So on the command line python Will run local python, Here, the next startup will fail , Therefore, you can save the following command to ~/.bashrc
alias python="/usr/bin/python3.6"

alias conda Of python You can run the following command

[email protected]:~$ whereis conda
conda: /home/zjq/anaconda3/bin/conda
alias python4=“anaconda Installation directory bin”

Personal test :
I use alias python="/usr/bin/python3.6" Will local python Use python Open up , then conda Of python Default , namely python3 open conda Of python,

pip The problem of
python -m pip --version # Show local python Package version
python3 -m pip --version # Show condapython Package version

5、 ... and . jupyter notebook

  • install pip install jupyter

5.1 jupyter stay conda Use in the environment

  • install ipykernel conda install ipykernel
  • Enter the corresponding environment conda activate scan
  • stay kernel Insert environment in scan
    python -m ipykernel install --user --name scan --display-name " stay kernel The name shown in "
  • function jupyter jupyter notebook perhaps jupyter-notebook
  • The results are shown in the following figure

5.2 jupyter Login password settings

  • method1 Set in the configuration file
jupyter notebook --generate-config # Generate configuration files 
vim /home/xibeiidaxue/.jupyter/jupyter_notebook_config.py
c.NotebookApp.token = '' # If it is set to blank, it means that no password is required for login 
c.NotebookApp.ip='*' # Set all IP All accessible 
c.NotebookApp.password = "" # password 
c.NotebookApp.allow_root = True # Allow root 
jupyter notebook --port 8888 # Run a specific port 8888 port 
  • method2 Set up directly
jupyter notebook --generate-config # Generate configuration files 
jupyter notebook password
# Enter password twice 

5.3 jupyter Common shortcut key

Cell Command mode currently supports Jupyter Notebook quick
Enter : Switch to edit mode
Shift-Enter : Run this unit , Select or insert ( the last one Cell When ) Next unit
Ctrl-Enter : Run this unit
Alt-Enter : Run this unit , Insert a new cell under it
Y : Unit goes to code state
M : Unit transferred to markdown state ( Not yet R Native state )
Up : Select the upper cell
K : Select the upper cell
Down : Select the cell below
J : Select the cell below
A : Insert a new cell above
B : Insert a new unit below
D,D : Delete the selected cell
L : Convert line number
Shift-Space : Scroll up
Space : Scroll down
Ctrl + X : shear / Cut line ( Empty selection )
Ctrl + C : Copy / Copy line ( Empty selection )
Ctrl + Delete / Backspace : Delete the right side 、 The words on the left
Alt + ↑ / ↓ : Up / Move line down
Shift + Alt + ↓ / ↑ : Up / Copy lines down
Ctrl + Shift + K : Delete row
Ctrl + Shift + \ : Jump to the matching bracket
Ctrl + ] / [ : Indent / Highlight line
Ctrl + ← / → : Cursor to prefix / Suffix
Ctrl + / : Switch line comments
Shift + Alt + A : Toggle block comment
Ctrl + H : lookup / Replace
Ctrl + D : Select a / Multiple ( identical ) word
Alt + single click : Insert multiple cursors
Ctrl + Alt + ↑ / ↓ : On top / Insert the cursor below
Ctrl + U : Undo the last cursor action
Shift + Alt + I : Inserts a cursor at the end of each selected line
Ctrl + L : Select the current line
Ctrl + Shift + L : Select all occurrences of the current word
Ctrl + F2 : Select all occurrences of the current word
Shift + Alt + → / Shift + Alt + ←: an / Narrow down the options
Shift + Alt + ( Drag the mouse ) : Rectangular block selection
Ctrl + K Ctrl + X : Trim trailing spaces

6、 ... and . The old Ubuntu install Python3.6

# Download the installation package on the official website 
1. wget http://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
# decompression 
2. tar -xvzf Python-3.6.4.tgz
# install 
3. cd Python-3.6.4
4. ./configure --with-ssl
# compile 
5. sudo make
6. sudo make install
# Create a soft connection , To look at first python3.6.4 Installation path for 
7. which python3 # /usr/local/bin/python3
8. sudo ln -s /usr/local/bin/python3 python

7、 ... and . python Package management

Problem description
We often configure the environment on a machine , You need to go to another machine to reconfigure python Environmental Science , In this way, it is necessary to appear some inexplicably every time python Package version error , So , You can use the following command , Put the current environment , python The package and version used are read into the file , Then insert directly into the environment of another machine through a command , Realize... In two machines python The package version of the environment is unified

# First redefine the package version to requirement.txt in 
pip freeze > requirements.txt
# In another environment , Install these packages 
among -r Is to install... From a given version
pip install -r requirements.txt

Problem summary

a. jupyter Unable to complete

jedi Version of the problem
pip install jedi==0.17


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved