Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the problems in building Python environment

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the problems in building the Python environment". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the problems in building the Python environment?"

01 Python uses positioning and the current role of IDE is still based on data analysis + algorithm, taking into account the engineering implementation. So the IDE combination of personal habits is JupyterLab+VSCode+Pycharm, in which JupyterLab is of course the main environment for data exploration and analysis, VSCode is used for viewing source code and document editing, and once it is determined that the algorithm process needs to output formal Python code files, Pycharm will be used. This order is not only the frequency of use from large to small, but also the volume and portability of IDE from simple to complex.

Note: Pycharm distinguishes Pro from Community. The former is more robust and powerful, but it needs to be used for a fee, while the latter is a free community version. I think the Community version is easy to use. In addition, many data practitioners admire the Anaconda environment, in fact, individuals do not think so, in addition to pre-installed Python and some third-party libraries, there is no substantial advantage. 02 Python install Python installation there is not much to speak of, just download the corresponding version from the official website, the latest version is 3.9.1, and according to the latest Python plan, there will be a large version iteration every year, that is, 3.10 will be launched in 2021 and 3.11 in 2022. But in fact, the personal favorite version is 3.7or 3.8.Python because most third-party libraries need to be installed separately, so its size is very small, only 20cm. A very noteworthy problem here is that the installation of Python distinguishes users by default, and the installation path is automatically located to the appdata directory of the user on disk C, and the installation path cannot be changed at will when the user is not an administrator. The effective solution at this point is to check the "install for all users" option, and the corresponding installation directory will be located to the default program files directory of most software.

After the installation of Python, if you do not install some third-party libraries, then the Python is actually very weak, so the second problem is how to install third-party libraries efficiently. In this regard, a brief summary is as follows:

Problems with 1.pip tool installation

Normally, installing Python installs the pip tool by default and adds it to the system environment variables, so that third-party libraries can be managed through the pip tool. Check the box during installation as follows:

If, for a variety of reasons, the system cannot use the pip command and the system prompts that pip is not an internal or external command, it is simply because the pip application is not added to the environment variable.

The solution to this problem is simple: find the pip.exe execution path in the Python installation directory and add it to the environment variable.

Problems with installing third-party libraries in 2.pip

Pip is a tool for managing third-party libraries. Common operations include install, uninstall and upgrade, in which install can distinguish between online download and installation and offline wheel file installation.

Install online. Online installation is very simple, but limited to the download speed, you generally need to configure the domestic download source of pip. Just create a pip folder in the user directory, then create a pip.ini file in the folder, and write the following 2 lines of code (here is to change the source of Tsinghua University as an example)

[global]

Index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Offline installation. Online installation is very convenient, but for some confidential or offline environments that are inconvenient for networking, a more effective method is offline installation. At this time, you can first prepare the package to be installed on a networked machine, and then execute the following three commands. The first two commands are used to prepare offline installation files on the networked machine, and the third command is used to perform offline installation on the target machine.

Export the list of installed pip: pip freeze > requirements.txt

Download the installation file pip download-d packages-r requirements.txt according to the list

Install pip install-- no-index-- find-links=packages-r requirements.txt offline according to the file and list

03 Jupyter Lab configuration

In general, when you install Python third-party libraries, you are sure to install Jupyterlab libraries as well. By default, after installation, you can directly type jupyter lab under the cmd command to start the browser and build the ipython running environment. There are still three issues to pay attention to here:

There was a space problem before 1.Jupyter lab. This is a small detail, in which in pip install, jupyterlab is concatenated to represent a package name, while when you type the jupyter command to start the browser, you need to write separately, where jupyter represents the command (jupyter.exe behind it) and lab represents the parameter. In addition to lab as a parameter, of course, another optional parameter is notebook

two。 By default, as long as the installation of jupyter lab is normal, typing jupyter lab in cmd will directly launch the browser to build the environment, but there are also abnormal situations, just as the pip command does not recognize it. When you encounter a jupyter command that does not recognize it, you still have to think that the path is not added to the environment variable. So the solution is the same as the previous pip command.

3. Modify the jupyter lab default working directory. In general, the default working directory after jupyter lab starts is the installation path, but this may be a scenario that most people don't want, so it naturally needs to be changed. The way to change is to execute the following command in cmd:

Jupyter lab-generate-config

Then open the newly generated configuration file, find the c.ServerApp.notebook_dir parameter, and change it to the destination path address, such as the D root directory in the figure.

04 VSCode configuration

VSCode is a code editor launched by Microsoft, more essentially a text editor, and similar applications such as Sublime and Notepad++. Although the functions are more or less the same, VSCode is gradually showing more and more competitive power due to Microsoft's strong endorsement and more and more plug-in additions.

Individuals are generally used to use it as a software to view the code, flexible use of ctrl+B shortcuts to find references is still very fast, but also integrated with Git and debug functions. Of course, to make it really work, you need to install some plug-ins. In the case of networking, you can easily find specified extension applications and install them by clicking the extension menu on the left, such as Chinese, beautify and Python language related plug-ins, which are almost necessary plug-ins.

Of course, the need to install plug-ins offline should also be considered, and VSCode naturally takes this scenario into account. Go to the following website (VSCode plug-in Market: https://marketplace.visualstudio.com/), enter the plug-in name, click on the go to details page, and click to download the extension on the right.

Then, similar to installing Python third-party libraries using the pip tool, you can directly install the VScode extension offline using the following command. Where xxx represents the previously prepared extension, and the code instruction can recognize the premise that the vscode.exe path is required to be added to the environment variable.

Code-install-extension xxx

Of course, there is also the configuration of Pycharm. Compared with Python, Jupyter, and VSCode, the installation of Pycharm is already highly integrated and does not require too much configuration. But what is worth in-depth study is the virtual development environment of Pycharm, which is also a sharp weapon of Pycharm, so it will no longer be carried out here.

Thank you for your reading. The above is the content of "what are the problems of building the Python environment?" after the study of this article, I believe you have a deeper understanding of the problem of building the Python environment, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report