Python3.7 venv不会创建虚拟环境目录 [英] Python3.7 venv does not Create Virtual Environment Directory

查看:227
本文介绍了Python3.7 venv不会创建虚拟环境目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方法在Windows中创建虚拟环境:

I'm trying to create a virtual environment in windows using:

python3 -m venv <dir-name>

运行上述命令后,当我在cmd中检查当前目录的内容时,看不到venv目录.该命令不会引发任何错误.

When I check the contents of the current directory in cmd after running the above command, I don't see the venv directory show up. The command doesn't throw any errors.

这个人似乎有同样的问题: Python venv未创建虚拟环境

This person seems to have had the same problem: Python venv not creating virtual environment

但是可以接受的答案是重新安装python,这对我不起作用.其他答案建议改为安装virtualenv,但据我所知,它与venv不同,它建议用于python3.3 +

But the accepted answer was to re-install python, which didn't work for me. Other answers suggest installing virtualenv instead, but as far as I know that is different from venv, which is recommended for python3.3+

有人知道如何用venv解决此问题吗?我已经尝试了python 3.6和3.7

Does anyone know how to solve this issue with venv? I've tried python 3.6 and 3.7

问题似乎是未使用PATH中设置的python.exe的位置.而是使用:C:\Users\GSI\AppData\Local\Microsoft\WindowsApps\python3.exe.我不确定如何修复我的环境变量.需要重启吗?我有很多东西在运行,但如有必要,我可以重新启动

The problem seems to be that the location of python.exe set in PATH is not being used. It is instead using: C:\Users\GSI\AppData\Local\Microsoft\WindowsApps\python3.exe. I'm not sure how to fix my environment variable. Is a restart required? I have quite a few things running but I can restart if it's necessary

Edit2 :我被要求发布以下命令输出的屏幕截图.如您所见,仅使用"python3"运行它们时没有输出.当我使用安装exe的完整路径运行命令时,我确实得到了ouptut:

I was asked to post a screenshot of the output of the following commands. As you can see, there is no output when I run them with just "python3". When I run the commands with the full path where the exe is installed, I do get ouptut:

我在这里找到了有用的信息: https://superuser.com/问题/1437590/typing-python-on-windows-10-version-1903-command-prompt-opens-microsoft-stor

Edit 3: I found a helpful post here: https://superuser.com/questions/1437590/typing-python-on-windows-10-version-1903-command-prompt-opens-microsoft-stor

当您没有安装python或将python添加到PATH变量中时,显然在CMD中键入"python"会打开Microsoft存储并在C:\Users\GSI\AppData\Local\Microsoft\WindowsApps中创建一个python.exe文件.我猜我是在初次安装python时但在添加PATH变量之前尝试执行python代码.

Apparently typing "python" into CMD when you don't have python installed/added to the PATH variable opens up the Microsoft store and creates a python.exe file in C:\Users\GSI\AppData\Local\Microsoft\WindowsApps. I'm guessing I tried executing python code when I first installed python but before I had added the PATH variable.

我按照帖子中的说明删除了python.exe和python3.exe的应用程序执行别名".这摆脱了WindowsApps中的exe文件(我无法手动将其删除).

I followed the instructions in the post to remove the "Application Execution Aliases" for python.exe and python3.exe. That got rid of the exe files in WindowsApps (I wasn't able to manually delete them).

但是,现在当我在CMD中键入where python3时,我得到: INFO: Could not find files for the given pattern(s).

However, now when I type where python3 in CMD, I get: INFO: Could not find files for the given pattern(s).

似乎没有选择我的PATH值.我尝试重新启动计算机,但是没有运气

It seems like it's not picking up my PATH values. I tried restarting my computer but no luck

推荐答案

它应该可以工作,我对其进行了多次测试( eg :

It should work, I tested it several times (e.g.: [SO]: PyWin32 (226) and virtual environments).
And yes, they are 2 different kinds of animals:

  • [Python 3.Docs]: venv - Creation of virtual environment
  • [PyPA.VirtualEnv]: Virtualenv.

示例:

e:\Work\Dev\StackOverflow\q059885771>sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***

[prompt]> set PY
PYTHONPATH=e:\Work\Dev\Utils\current

[prompt]> dir /b

[prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -c "import sys, venv;print(sys.version);print(venv)"
3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)]
<module 'venv' from 'c:\\Install\\pc064\\Python\\Python\\03.07.06\\lib\\venv\\__init__.py'>

[prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT]
            ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR

[prompt]> time<nul
The current time is: 21:51:57.12
Enter the new time:
[prompt]> "c:\Install\pc064\Python\Python\03.07.06\python.exe" -m venv ".\venv_dir"

[prompt]> echo %errorlevel%
0

[prompt]> time<nul
The current time is: 21:52:10.54
Enter the new time:
[prompt]>
[prompt]> dir /b
venv_dir

[prompt]> "venv_dir\Scripts\python.exe"
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z


[prompt]>

注意事项(注意事项):

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆