大家好!
有点新venvs。我通过 Powershell 创建了一个,并使用 .bat 文件激活,它正常工作,但它似乎也像笔记本或 txt 文件一样在我的 VS 中打开 Activate.ps1。
我可以关闭或离开它,程序运行正常,但我不知道这是 Python/.bat/.ps1 错误还是正常行为,但我不想打开它,如果可能的话。
搜索后我在这里找到这篇文章:Typing venv scripts activate.ps1 open Notebook auto
但是帖子有 1 个答案不能解决我的问题,而且它有点不同,因为即使这个文件自动打开我的程序也能正常工作
-使用 python 3.10.4
venv创作:
cd C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\
python -m venv "C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\Nome_do_Robo"
Nome_Projeto\Nome_do_Robo\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r "C:\Users\Me\Documents\DATA_SCIENCE\Projetos\_infos\Requirements\requirements_Robo.txt"
.bat文件:
@echo off
setlocal
cd C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\Nome_do_Robo\Scripts\
set PYTHONPATH=C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\Nome_do_Robo\Scripts\
set pathLog=C:\Users\Me\Documents\DATA_SCIENCE\Projetos\_Logs\Nome_Projeto
.
.(Others string variables)
.
set resultado=C:\Users\Me\Documents\DATA_SCIENCE\Projetos\_Resultados_dos_Robos\Nome_Projeto\
taskkill /IM python.exe /F
C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\Nome_do_Robo\Scripts\Activate.ps1 &
python C:\Users\Me\Documents\DATA_SCIENCE\Projetos\Nome_Projeto\ScrapStuff.py
我在 Powershell 和 VS Studio 中运行了 .bat 文件,两者都打开了以下注释(看起来像一个“how-to venv help”文件)
(文件很长,但如果需要,我会粘贴全部内容)
<#
.Synopsis
Activate a Python virtual environment for the current PowerShell session.
.Description
Pushes the python executable for a virtual environment to the front of the
$Env:PATH environment variable and sets the prompt to signify that you are
in a Python virtual environment. Makes use of the command line switches as
well as the `pyvenv.cfg` file values present in the virtual environment.
.Parameter VenvDir
Path to the directory that contains the virtual environment to activate. The
default value for this is the parent of the directory that the Activate.ps1
script is located within.
.Parameter Prompt
The prompt prefix to display when this virtual environment is activated. By
default, this prompt is the name of the virtual environment folder (VenvDir)
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
.Example
Activate.ps1
Activates the Python virtual environment that contains the Activate.ps1 script.
.Example
Activate.ps1 -Verbose
Activates the Python virtual environment that contains the Activate.ps1 script,
and shows extra information about the activation as it executes.
.Example
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
Activates the Python virtual environment located in the specified location.
.Example
Activate.ps1 -Prompt "MyPython"
Activates the Python virtual environment that contains the Activate.ps1 script,
and prefixes the current prompt with the specified string (surrounded in
parentheses) while the virtual environment is active.
.Notes
On Windows, it may be required to enable this Activate.ps1 script by setting the
execution policy for the user. You can do this by issuing the following PowerShell
command:
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
For more information on Execution Policies:
https://go.microsoft.com/fwlink/?LinkID=135170
#>
Param(
[Parameter(Mandatory = $false)]
[String]
$VenvDir,
[Parameter(Mandatory = $false)]
[String]
$Prompt
)
<# Function declarations --------------------------------------------------- #>
我有 3 个基本脚本在这个 venv 中运行,如果需要我也可以分享它
任何帮助将不胜感激!
谢谢!
删除 venv 和文件夹,重新启动桌面并在其他文件夹中重新创建整个 venv。