current position:Home>A brief note on the method of creating Python virtual environment in Intranet Environment

A brief note on the method of creating Python virtual environment in Intranet Environment

2022-01-31 09:51:46 Itchy rat Gou planning

This is my participation 11 The fourth of the yuegengwen challenge 2 God , Check out the activity details :2021 One last more challenge

I'm going to do a desktop programming recently , Because our company is in the Intranet environment , Want to use Electron too troublesome , Ready to use PyQt try .

In the company, the computer is installed Anaconda in the future , perform conda create -n py To create a new python My virtual environment is wrong .

Find out conda create We'll have to connect when we're ready conda Even if the official website uses Tsinghua image, it is also an external network , It is the same as the original network of our company python The source is pypi Of .

here , After searching , Found three solutions :

  1. Use python package virtualenv
  2. Build a source on the intranet
  3. Offline installation

The third way is to treat the symptoms but not the root cause , The second requires too much space , Therefore give up .

But the first one can reuse the original of our intranet pypi Source , So take the first approach .

But I stepped on a pit here :

Our image is based on nexus Of , When you need to copy the address , The pop-up address is shaped like http://ip_address:port/nexus3/repository/pypi-public/ Of , Configure the intranet source according to the following instructions in the network tutorial ,

pip config set global.index-url http://ip_address:port/nexus3/repository/pypi-public/
 Copy code 

And then execute the command pip install virtualenv The package cannot be found after an error is reported .

After groping , Found a mistake , Can only be modified again , Open folder C:\Users\{ user name }\AppData\Roaming\pip modify pip.ini (linux Address ~/.pip/pip.conf

[global]
trusted-host = { Intranet source ip Address or domain name }
index = http://ip_address:port/nexus3/repository/pypi-public/pypi
index-url = http://ip_address:port/nexus3/repository/pypi-public/simple
 Copy code 

Execute command again pip install virtualenv Successfully installed after . In the configuration file above ,trusted_host The configuration of this item is because if this item is not added pip install I will report warning, Say that the current site uses http No https Unsafe or something ....

After installing the package , Enter a directory to create a virtual environment , I chose Anaconda In the catalog envs Folder .

Execute... In the current directory virtualenv pyenv1, After execution , There is one more in place pyenv1 Folder .

In theory , Execute to pyenv1\Scripts Under the table of contents activate The virtual environment is ready to be activated .

But here I stepped on another pit ...

Because in Windows Inside, I put Anaconda Install under directory Scripts The folder is also added to the environment variable , So when I execute pyenv1\Scripts Execute under directory activate I didn't respond at all . At first I thought it was the wrong instruction , But after reading a lot of tutorials, I can't see what's wrong ...

Later, it was found that it was because of the execution of activate, perform ./actvate After that, I successfully cut the environment to pyenv1

perform deactivate You can exit the virtual environment .

ps: The flag of whether it is in the virtual environment can refer to whether there is one on the left of the command line (your_env_name).

copyright notice
author[Itchy rat Gou planning],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310951433990.html

Random recommended