One article teaches you how to configure Python handy

The popularity of Python has gradually increased in recent years, and Python is also listed as a general education course in many colleges and universities. The reason why it is so popular is its efficiency, simplicity, ease of use, and powerful third-party libraries. Nowadays, it is widely used in web development, artificial intelligence, big data, etc. Whether you like it or not, no matter how much you complain, if you want to engage in artificial intelligence, it is still difficult to bypass Python. Although julia and Go have been fired very hot in the past two years, they still cannot shake the status of Python in artificial intelligence.

Table of Contents

  • Python interpreter
  • IDEs
  • pip proxy
  • virtual environment

Python interpreter

A programming language involves a compiler or an interpreter. A program written in a compiled language such as C/C++ needs to be converted from a source file into a machine language used by a computer. After being linked by a linker, a binary executable is formed. document. When running the program, the binary program can be loaded from the hard disk into the memory and run. But for Python, the python source code does not need to be compiled into binary code, it can run the program directly from the source code. To execute Python, you need to use a Python interpreter. According to the version, the Python interpretation system can be divided into:

  • 2.x
  • 3.x

The 2.x version is no longer maintained, so most projects currently use 3.x. I personally recommend using the 3.6.x version. 3.7.2 is the latest version, but there will be such and such in the use process errors, there will be incompatibility and other problems, and there are some problems in versions 3.5.x and below:

  • The prefix f format string is only supported after 3.6.x
  • 3.5.x installation-related dependencies are prone to failure when installing toolkits

Installation steps:

  • download interpreter

  • Double click to install

Remember to check pip, which is a package management tool for Python and will be used frequently

IDE

IDE (Integrated Development Environment, integrated development environment), currently there are many IDEs for Python, such as vs code, eclipse, atom, anaconda, IDEA, etc. I personally do not recommend using the above-mentioned IDEs, of course, if you like these IDEs very much. For developing Python, I only recommend pycharm and jupyter notebook. Needless to say, this is the most powerful IDE for Python. Jumping, linking third-party libraries, speed, integration, debugging, etc., it can be said that pycharm is excellent in most aspects of Python development, while vs code, eclipse, anaconda, atom are only in one or several aspects The performance is ok. First of all, vs code is very slow in linking third-party libraries, function prompts, etc., and it is easy to get stuck under the server. Eclipse needs additional configuration of Python plug-ins. Anaconda integrates too many packages, many of which are not used by oneself. Yes, but I’m not interested, so I think it’s better to configure vim to use these IDEs. If you don’t like to install an IDE for each language, but like an IDE that supports different languages like eclipse, I support the use of IDEA, which belongs to the same product as pycharm, and has many features in common.

Advantages of pycharm:

  • feature rich
  • prompt speed
  • Powerful bookmark and jump function
  • Efficient debugging
  • Students can sign up to use the Pro version for free

pycharm installation steps:

  • download pycharm

If you have not purchased the professional version, you can download the community version for free:

If you have a school mailbox, you can register for the educational version, which is no different from the professional version:

  • to install

Double-click the executable file, select the installation directory to install it.

  • configure interpreter

setting->Project->Project Interpreter

Select the Python interpreter installed above in the red box

To check, because Python generates a virtual environment by default, use the interpreter in the virtual environment

Advantages of jupyter notebook:

  • interactive debugging
  • Switch between Markdown and code at any time, and write code while taking notes

jupyter notebook installation steps:

  • open cmd
  • install with pip
pip install jupyter notebook

pip proxy

Pip is a package management tool for Python. Whether you install it under cmd or terminal or use pycharm to install packages, pip will be called.

The default proxy is to download and install the package from pypi, and the speed will be relatively slow, so you need to configure the pip proxy, so that the speed will be greatly improved, as shown in the figure, after using the default download speed of several hundred k, configure After the proxy, it can reach 2.1M/s.

pip proxy configuration steps:

  • create pip folder

Create a pip directory in the personal directory, such as C:\Users\li,

  • Create proxy file

Enter the C:\Users\li\pip directory, create a file named [pip.ini], open it, copy the following text into it and save it:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Virtual environment

Python, like other programming languages, faces a transplant problem. If you want to transfer a completed project to other computers, nodes or make the project into a docker image, you need to reconfigure the development environment and reinstall the used in the project. For third-party toolkits, it will be very troublesome to compare and install them one by one. When we use the system environment, the packages installed by pip are all installed in the site-packages under the Python path. If the requirement.txt is generated, the site will also be included. All packages under -packages will be included, which is why the virtual environment is used, and an independent environment can be created for different projects, which is convenient for later transplantation.

There are two main types of Python virtual environment management tools:

  • virtualenv
  • pipenv

Both of the above tools can be installed using pip:

pip install virtualenv
pip install pipenv

How to choose virtualenv and pipenv? I think it’s down to personal preference.

virtualenv is older and older, and the steps are as follows:

  • Create a virtual environment
virtualenv test_env
  • Activate the virtual environment
test_env\Scripts\activate
  • Generate requirements

After activating the virtual environment, you can enter the virtual independent environment for development. If you want to go to another system after the development is complete:

pip freeze > requirement.txt

In this way, the packages and versions in the virtual environment are read into requirement.txt. If you want to install these packages in another system configuration, you can use pip:

pip install -r requirement.txt

Pipenv is more powerful. Pipenv to Python is equivalent to Php to Composer, Nodejs to npm, and Golang to dep. Pipenv is equivalent to the combination of virtualenv and pip. Two points explain the advantages of pipenv compared to virtualenv:

  • Every time virtualenv is developed, it needs to manually execute a pip freeze > requirement.txt to read the latest environment of the project into the requirement. If you forget it, you will not be able to get the latest configuration environment. Pipenv can monitor the changes of the environment in real time and put the latest The environment is read into the Pipfile.
  • virtualenv needs to activate the virtual environment first, and then configure it with pip, while pipenv can directly use pipenv to configure the environment

pipenv usage steps:

  • create
pipenv check

This is the directory where the Pipfile will be generated.

  • Start the virtual environment
pipenv shell
  • Install third-party packages
pipenv install **
  • Exit the virtual environment
exit
  • View all packages
pip list
  • View package dependencies
pipenv graph
  • View virtual environment path
pipenv --venv
  • Uninstall the installation package
pipenv uninstall

The above are two commonly used virtual environment management tools. Pipenv is more powerful in comparison, and I personally use virtualenv for a longer time, so I am also used to using virtualenv. Everyone can choose according to their own preferences.

About Python technology reserves

Learning Python well is good whether it is employment or sideline business to make money, but to learn Python, you still need to have a study plan. Finally, everyone will share a full set of Python learning materials to help those who want to learn Python!

For beginners with 0 basics:

If you are a zero-based novice, you can consider getting started with Python quickly.

On the one hand, the learning time is relatively short, and the learning content is more comprehensive and concentrated.
On the other hand, you can find a learning plan that suits you

Including: Python activation code + installation package, Python web development, Python crawler, Python data analysis, artificial intelligence, machine learning and other tutorials. Take you to learn Python systematically from zero foundation!

Introduction to zero-based Python learning resources

Python learning route summary

The technical points in all directions of Python are sorted out to form a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources according to the above knowledge points to ensure that you can learn more comprehensively. (Get the full set of tutorials at the end of the article)

Python essential development tools

Reminder: The space is limited, the folder has been packed, and the way to obtain it is at the end of the article

Python learning video 600 collection

Watching the zero-based learning video is the fastest and most effective way to learn. Following the teacher’s ideas in the video, it is still very easy to get started from the basics to the in-depth.

100 Python exercises

Check the learning results.

Interview questions

This full version of the full set of Python learning materials has been uploaded to CSDN. If you need it, you can scan the QR code of CSDN official certification below on WeChat to get it for free [guaranteed 100% free]