简体   繁体   English

如何运行此 python 脚本?

[英]How do I run this python script?

I'm new to python, and I was wondering if you could help me run a python script.我是 python 的新手,我想知道您是否可以帮我运行 python 脚本。 I'm trying to run a script called PunchBox from Github: https://github.com/psav/punchbox .我正在尝试从 Github 运行一个名为 PunchBox 的脚本: https://github.com/psav/punchbox So far, I have Python 3.9.5 and Git Bash.到目前为止,我有 Python 3.9.5 和 Git Bash。

In the GitHub page, it says:在 GitHub 页面中,它说:

To install, clone the repo, cd into it and then execute the following:要安装,请克隆 repo,cd 到其中,然后执行以下命令:

virtualenv -p python2 .pb2
source .pb2/bin/activate
pip install -U pip
pip install .

What does this mean exactly?这到底是什么意思? Where do I run this code?我在哪里运行这段代码?

So far, I tried downloading the zip file from GitHub, installing Python 3.5.9, using cmd, finding the directory with cd, and running that code; So far, I tried downloading the zip file from GitHub, installing Python 3.5.9, using cmd, finding the directory with cd, and running that code; but got an error:但出现错误:

Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository.例外:此项目的版本控制需要 sdist tarball,或访问上游 git 存储库。 It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. setup.cfg 中的 package 名称与提供给 pbr.version.VersionInfo 的参数之间也可能存在不匹配。 Project name punchbox was given, but was not able to be found.给出了项目名称打孔器,但无法找到。

error in punchbox setup command: Error parsing C:\Users\Mi\Downloads\punchbox-master\punchbox-master\setup.cfg: Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. punchbox 设置命令中的错误:解析 C:\Users\Mi\Downloads\punchbox-master\punchbox-master\setup.cfg 时出错:异常:此项目的版本控制需要 sdist 压缩包或访问上游 ZBA9F11ECC3497D9993B933FDC2BD61EZ 存储库。 It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. setup.cfg 中的 package 名称与提供给 pbr.version.VersionInfo 的参数之间也可能存在不匹配。 Project name punchbox was given, but was not able to be found.给出了项目名称打孔器,但无法找到。

There's also a requirements.txt that lists additional scripts needed:还有一个 requirements.txt 列出了所需的其他脚本:

pre-commit
click
mido
pbr
PyYAML
svgwrite

Do these install automatically upon running the script for the first time?第一次运行脚本时这些会自动安装吗?

I'm a little confused why I'm getting an error.我有点困惑为什么我会出错。 Do you know what I'm doing wrong?你知道我做错了什么吗?

Thank you so much!太感谢了! Giovanni乔瓦尼

I assume you are new to programming.我假设您是编程新手。 You have to write these lines in a terminal.您必须在终端中编写这些行。

On Windows, it is Command Prompt or PowerShell Applications (latter preferred).在 Windows 上,它是Command PromptPowerShell Applications (后者首选)。 On macOS, it is terminal在 macOS 上,它是terminal

Copy all these lines at once, and paste them to your preferred terminal.一次复制所有这些行,并将它们粘贴到您的首选终端。 The terminal will automatically run these one after the another.终端会一个接一个地自动运行这些。

FYI : Venv is a python package to create a virtual environment.仅供参考:Venv 是一个 python package 创建一个虚拟环境。 The preceding commands set up the environment.前面的命令设置环境。 Now install the required dependencies using this command instead of the last command (现在使用此命令而不是最后一个命令安装所需的依赖项( pip install. ) )

pip install -r requirements.txt

Based on your comment, it looks like you don't have virtualenv installed in your system.根据您的评论,您的系统中似乎没有安装virtualenv You may install it using the command pip install virtualenv .您可以使用命令pip install virtualenv安装它。

Now, as you are using a Windows machine, you may open a Command Prompt or Windows PowerShell window and navigate to the directory where your cloned project resides.现在,当您使用 Windows 机器时,您可以打开Command PromptWindows PowerShell Z05B8C74CBD902FBF2DE4C1A352 并导航到您的克隆项目所在的目录。 Now, execute the following commands.现在,执行以下命令。

virtualenv -p python2.pb2 virtualenv -p python2.pb2
.pb2\Scripts\activate.bat .pb2\Scripts\activate.bat
pip install -U pip pip 安装-U pip
pip install -r requirements.txt pip install -r requirements.txt

Once you are done working in your virtual environment (which is named .pb2 ), you may close it by executing deactivate command.在虚拟环境(名为.pb2 )中完成工作后,您可以通过执行deactivate命令将其关闭。

@Giovanni T. See, as far as you have installed Python and also downloaded the GitHub Repository as a zip file. @Giovanni T.见,只要您安装了 Python 并且还下载了 GitHub 存储库作为 zip 文件。

pip install -r requirements.txt Just run this command. pip install -r requirements.txt运行这个命令即可。

Please make sure that the directory is pointing to the folder where this requirements.txt file is stored.请确保该目录指向存储此 requirements.txt 文件的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM