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

How to move the python virtual environment to an offline machine on pycharm

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to move the python virtual environment to the offline machine on pycharm. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Steps of concentration

Execute in the Terminal of Pycharm:

View existing packages into requirements.txt

Pip freeze > requirements.txt

Generate dependency packages

D:\ machangwei\ venv\ Scripts\ python.exe-m pip download-d whl-r requirements.txt #-d specifies the directory to which the packages in the virtual environment will be installed, and if not, it will create a new directory. -r specify the dependency package file found in the previous step

In the target machine:

Copy project files except for venv

Open the project

Create a new venv

Execution

The details of pip install-no-index-find-links=whl-r requirements.txt steps are as follows: 1. Create a new pyhon virtual environment to be migrated

1.1 create a new virtual environment:

1.2 create a new python file

Right-click to run

1.3 query the virtual environment

View package

It's the only one right now.

The comparison catalogue is consistent.

The package cannot be imported. The following is the directory of python's interpretation power.

No

1.4 add an installation package in a virtual environment

Installation

Installation succeeded

Import normally, and can be used

1.5. command to view existing packages and create requirements.txt files

Execute in the Terminal of Pycharm:

View existing packages into requirements.txt

Pip freeze > requirements.txt

Generate dependency packages

1.6. Download all dependent packages in the virtual environment to the specified directory

Https://pypi.tuna.tsinghua.edu.cn/simple/

Do not specify a mirror source, specified a failure. Pycharm has been set up to add the above Tsinghua source. Download the previously installed psutil to whl

D:\ machangwei\ venv\ Scripts\ python.exe-mpip download-d whl-r requirements.txt

D:\ machangwei\ venv\ Scripts\ python.exe-mpip download-d whl-r requirements.txt-I http://mirrors.aliyun.com/pypi/simple--trusted-hostmirrors.aliyun.com

2. Migrate the python virtual environment to the private network machine

2.1 upload files to the private network machine

In the target machine:

Copy project files except for venv

2.2 create a new project virtual environment

Open the project

Create a new venv

2.3 copy the environment files to be migrated into the new intranet virtual environment, and execute the installation command

Pip install-no-index-find-links=whl-r requirements.txt

E:\ suppose it is a new private network machine\ machangwei\ venv\ Scripts\ pip.exe install-- no-index-- find-links=whl-r requirements.txt

Whl is the directory where the installation package is located, and what installation packages are written in requirements.txt

The new environment is like this.

If there is a problem, use the absolute path command of the virtual environment

Installation succeeded

2.4 execute the program to verify that it is normal

Instead of right-clicking the execution file, add the configuration directly (or right-click to run the program, this method is not configured successfully)

There is no name. Change the name.

Execution is not allowed.

Right-click to run

That's it. The one in the upper right corner is automatically generated. It's ready to run.

2.5 Notebook network disconnection test, reconstruction of a virtual environment on the intranet machine, is also successful.

Now create a new directory

Install the directory as a virtual environment

Copy the virtual environment files from elsewhere.

Disconnect one's own network

Then use the pip of the virtual environment to install the installation package of other virtual environment, successfully install, and realize the migration of the python virtual environment to the host without extranet. Have time to verify that there is a difference on linux.

3. Problems encountered in the process of operation

The establishment of a problem

Open the project

New venv, because there are files in the new virtual environment, the virtual environment created is problematic.

On how to achieve python virtual environment on pycharm to the offline machine to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Development

Wechat

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

12
Report