程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

What is Python doing using venv virtual environment + activation and deactivation in pycharm+ How to use PIP without activating the environment

編輯:Python
  • python3.6 And above have been installed by default venv
  • stay pycharm Use in , The default location is under the current project directory :


pip After some bags :

  • Why virtual environments ?
  • Conflicts between different versions of the installation package . Because the dependent packages will be installed at the same time , But when uninstalling, only one .

What are activation and deactivation doing ?

  • use venv Of python.exe perform py Code , It has nothing to do with whether to activate the virtual environment .activate What matters is pip Install the module ( library ) When .
  • take “*\python\Scripts” Added to the path After the environment variable

pip.exe And pip modular

pip Actually, it's just python A module of , Also with .py It's a suffix python The library files . And is located in "*\python\Lib\site_packges" Under the document , Here is the folder where the third-party library is located .Scripts Medium pip.exe The function of is to call pip, It is convenient for us to use directly on the command line pip library .

python pip.exe - How to use without activating the environment pip

 When the user enters... On the command line pip after , function pip.exe Executable file , It will bring “*\python\python.exe” And “*\python\Scripts\pip.exe” Connect and execute on the command line .
pip.exe Will be looking for Lib\site_packages Medium pip In the library __main__.py File and finally return its path information , So it's equivalent to “*\python\python.exe” + “* \__ main__.py”, In fact, you can also run directly in this way pip, It's just a little bit of trouble .
Of course, you can also enter "*\python.exe" + " *\pip.exe " call pip modular , It's all the same .

windows

python Built-in tools pip.exe,
be located python Installation directory script subdirectories D:\python\Scripts
Command line input :pip.exe install ***

linux

  • /.conda/envs/envname/bin/pip list &> list.txt
  • /.conda/envs/envname/bin/pip3 install onnxruntime-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple –-trusted-host mirrors.aliyun.com
  • /bin/pip3 --default-timeout=100 install onnxruntime-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple &> watch.txt

Reference and more

  • Main reference :pip The principle of calling from the command line

  • Installation is not complete , Only by understanding the virtual environment can we really master Python Environmental Science

  • essays —— Self made python compiler ——pip.exe Copy modification of https://blog.csdn.net/Cc6661366613/article/details/124007603
    Hanging and exploding the sky ,linux On python Virtual environment migration method https://www.jianshu.com/p/ef54a30eb936

  • vscode Use in venv

 besides , It can also be done through "python -m pip" call pip, This method of execution is python.exe Features included ,-m It means “ call moudule”, You can also call other modules in this way ( The premise is that the module also supports independent execution ), It will directly find and mobilize site_packages Inside pip modular , And it doesn't use pip.exe.
So look at it like this , call pip There are many ways to use the library , In fact, the essence is to pip In the library __main__.py File entry python The interpreter performs .
Be careful : If changed python Name of the folder , So even if the system environment variables are adjusted accordingly , You can no longer enter directly pip call pip modular . because pip.exe Does not automatically adjust the path of the call itself
And still use “*\python\python.exe” This original python Interpreter path . So don't change it easily python Name of the folder .

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved