Python installation guide anaconda, python, Jupiter

Keywords: IDE

1, Anaconda installation

setup script

  1. Download installer
    https://www.anaconda.com/products/individual

  2. After downloading, click anaconda3-2019.07-windbos-x86_ 64.exe to install, select the path, check the add environment variable (you don't need to configure it yourself), and wait for the installation to complete

  3. Verify that the installation is successful: open the command line as an administrator, enter conda, and press enter. The installation is successful when the following conditions occur.

Note: do not install anaconda to disk C. Because you will have many virtual environments behind you and install many packages; In addition, it is recommended to add the conda command to the environment variable.

Use of command line

  1. Enter activate to directly enter a default virtual environment of root, where all packages can be installed to create a universal environment.
  • First sort out the commands about package management
# Lists the packages installed in the current environment, which is very common
conda list

# During the experiment, if some packages are not found, install them directly
conda install package_name  # Version number is also allowed
pip install package_name

# If the wrong version is found, you want to uninstall the swap
conda remove package_name
pip uninstall package_name

# Update package
conda update package_name
  1. Multiple virtual environments are used. The specific command line is as follows:
# View existing common virtual environments
conda env list

# The new virtual environment can specify the python version and some package versions
conda create -n env_names package_names   # conda create -n tfenv python=3.7

# When you enter the virtual environment, you are faced with operations on some packages, which are the related commands of the above packages
activate tfenv

# Leave the virtual environment
deactivate

# Delete virtual environment
conda env remove -n env_name

3. Shared environment, which allows others to install all packages used in the project and ensure that the versions of these packages are correct

# Save the packages installed in the current environment as YAML files
conda env export > environment.yaml

An exported environment file will be found in the current directory

How to use the exported environment file?

activate tfenv

# Install all packages
conda env update -f=/path/to/environment.yaml  

If you use pip instead of conda, you can export a txt file and install:

pip freeze > requirements.txt  # export file

# Then include the file in the code base of the project. Other project members can use the file to install the same development environment as me even if conda is not installed on his computer
pip install -r /path/requirements.txt

2, Pycham installation

  1. Download installation package
    https://www.jetbrains.com/pycharm/download/other.html
  2. Installation procedure reference
    https://cloud.tencent.com/developer/article/1504718
  3. Solve the problem of probation period

2, Jupyter installation and related configuration

  1. After anaconda is installed, there will be jupyter notebook in the default root environment, but after the new virtual environment is created, we need to reinstall jupyter notebook. The command is simple:
pip install jupyter notebook
  1. Modify the default workspace and use the Jupiter notebook on Windows. Unlike Linux, the default workspace is the directory in which Linux is started. However, this is not the case in Windows. Generally, the configuration file of Jupiter is modified. If not, open the command line and generate it through the following command:
jupyter notebook --generate-config

A jupyter will be generated under the. Jupyter directory under the user on disk C_ notebook_ Config.py file:

Open jupyter_notebook_config.py, find c.Notebook, create your new work path, uncomment, and remove the # before C.

  1. By modifying the configuration file, you can not only modify the default workspace, but also modify the default, start the browser, and then open Jupiter_ notebook_ Config.py found App.browser = '', add the following three lines of code below this line:
import webbrowser
webbrowser.register("chrome",None,webbrowser.GenericBrowser(u"C:\ProgramFiles (x86)\Google\Chrome\Application\chrome.exe"))
c.NotebookApp.browser = 'chrome'
  1. Install some extensions:
conda install -c conda-forge jupyter_contrib_nbextensions

At this point, open jupyter to have some extended functions:

A good jupyter theme:

pip install jupyterthemes

# A good theme
jt -t monokai -f fira -fs 13 -cellw 90% -ofs 11 -dfs 11 -T -N
  1. Use of jupyter
    Common commands

Reference link
https://blog.csdn.net/ITLearnHall/article/details/81708148/?utm_medium=distribute.pc_relevant.none-task-blog-2

Posted by mrjonnytou on Sun, 31 Oct 2021 04:16:18 -0700