无法在Windows 10的PowerShell中的virtualenv上运行python

时间:2018-07-10 23:48:18

标签: python windows powershell pip virtualenv

Python和pip在PowerShell中可以正常工作,但是在激活virtualenv时运行它会有所不同。我收到这些错误:

(<project_name>-env) PS D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\Scripts> python
Traceback (most recent call last):
  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\lib\site.py", line 703, in <module>
    main()
  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\lib\site.py", line 692, in main
    aliasmbcs()
  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\lib\site.py", line 515, in aliasmbcs
    import locale, codecs
  File "D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\lib\locale.py", line 17, in <module>
    import functools
ImportError: No module named functools
(<project_name>-env) PS D:\Kerja\HIT\Python Projects\<project_name>\<project_name>-env\Scripts> pip
Fatal error in launcher: Unable to create process using '"'

使用PowerShell时如何在virtualenv中成功运行python和pip?

1 个答案:

答案 0 :(得分:-2)

我找到了答案!事实证明,当我在PowerShell上使用virtualenv时,它会优先使用python和来自virtualenv的pip优先于PATH环境变量。

我之前提到的python和pip以及/<environment_name/Scripts/>activate脚本位于deactivate文件夹中。删除python.exe和pip.exe或仅重命名即可。

请注意,它可能会影响pip freeze -l。不过我不确定。