在win10下建立Python的虚拟环境

2019-05-12  本文已影响0人  4thirteen2one

64位win10,在PowerShell中打开,键入命令,结果显示这样的:

PS E:\qt\pyqt> python -m venv tutorial
PS E:\qt\pyqt> .\tutorial\Scripts\activate
.\tutorial\Scripts\activate : File E:\qt\pyqt\tutorial\Scripts\Activate.ps1 c
annot be loaded because running scripts is disabled on this system. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?
LinkID=135170.
At line:1 char:1
+ .\tutorial\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

提示中给出的链接 https:/go.microsoft.com/fwlink/? LinkID=135170打开之后是关于执行政策的

报错的原因大概是权限相关的问题。
To change the execution policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option.
To change the execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser"。

OK,那我们键入命令 Set-ExecutionPolicy -Scope CurrentUser

PS E:\qt\pyqt> Set-ExecutionPolicy -Scope CurrentUser

cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust.
Changing the execution policy might expose you to the security risks
described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the
execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "N"):y
PS E:\qt\pyqt> .\tutorial\Scripts\activate
(tutorial) PS E:\qt\pyqt> deactivate
PS E:\qt\pyqt>

大功告成,虚拟环境搭建成功。

搭建成功后文件夹下的组织结构是这样的:

(pyqt) PS E:\qt> dir .\pyqt\


    Directory: E:\qt\pyqt


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2019/5/12     22:59                .idea
d-----        2019/5/12     16:00                Include
d-----        2019/5/12     16:00                Lib
d-----        2019/5/12     16:52                Scripts
-a----        2019/5/12     16:00             73 pyvenv.cfg


(pyqt) PS E:\qt>

这种组织结构大概就是按照Python本身安装目录下的组织结构来安排的:

(pyqt) PS E:\qt> dir C:\Python


    Directory: C:\Python


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2019/4/13     20:36                DLLs
d-----        2019/4/13     20:36                Doc
d-----        2019/4/13     20:36                include
d-----        2019/4/13     20:36                Lib
d-----        2019/4/13     20:36                libs
d-----        2019/5/12     14:19                Scripts
d-----        2019/4/13     20:36                tcl
d-----        2019/4/13     20:36                Tools
-a----        2019/3/25     22:26          30195 LICENSE.txt
-a----        2019/3/25     22:26         665470 NEWS.txt
-a----        2019/3/25     22:23          99856 python.exe
-a----        2019/3/25     22:23         421888 python.pdb
-a----        2019/3/25     22:22          58896 python3.dll
-a----        2019/3/25     22:22        3748368 python37.dll
-a----        2019/3/25     22:22        9490432 python37.pdb
-a----        2019/3/25     22:23          98320 pythonw.exe
-a----        2019/3/25     22:23         421888 pythonw.pdb
-a----        2019/3/25     21:22          89752 vcruntime140.dll


(pyqt) PS E:\qt>

下面来解释一下各文件夹的作用:

上一篇 下一篇

猜你喜欢

热点阅读