Windows 用户如何运行一个 GitHub 上的 Python 脚本?
不知道是否描述清楚了... 对于一个丝毫没有接触过编程的小白用户,应该怎么运行这样一个脚本呢?
回复内容:
感谢邀请,不胜荣幸。的确,在开发者眼中,这个问题相当简单,但是针对普通用户,确实是一个让人不知所措的问题。这也是应用分发商店的伟大之处。
本问题中其实包含两个问题:
1. 如何使用GitHub中的代码?
2. 如何运行Python程序?
问题1:
GitHub针对的更多是开发用户而不是普通用户。对于初使用Github的开发用户,可以参考「怎样使用 GitHub ?」中的回答。不过如果是普通用户,只是希望使用某项目中的程序(以我在另一个问题中的回答「如何快速地在知乎上删除所有提问及最新动态?」为例),可以参考以下步骤:
打开项目地址页面,此处为leodas/ZhihuHelper · GitHub,在页面右边选择“Download Zip”下载该项目的源代码,如下图。

问题2:
运行Python项目,首先要确保该计算机具有合适的Python运行环境。目前主流Python项目有两个版本:Python 2.6+和Python 3+。两个版本间的代码可能会有一些兼容性上的问题,需要针对具体的项目提供不同的运行环境。在本例中,代码基于Python 2.7.6+编写。若使用者的操作系统为Mac OS或GNU/Linux,那么一般无需额外安装Python运行环境。若为Windows,可能需要在Python官方网站下载以及安装运行环境。可以参考以下步骤进行安装:
进入下载页面Download Python,针对不同的Windows版本(32位/64位),选择与之对应的安装程序,如下图。

如果需要运行的项目中还需要其它第三方库的支持,则需要安装所需的第三方库。在此例中,该项目还需要安装Requests与BeautifulSoup,安装这两个第三方库可以参考以下步骤:
进入Requests下载与安装页面,滚动页面找到下载链接,如下图。


使用快捷键Win+R开启运行窗口,输入cmd并执行,打开一个命令行窗口。
我的Python运行环境安装在C:\Python27\,Requests与BeautifulSoup解压路径分别为D:\src\kennethreitz-requests-969195a\、D:\src\beautifulsoup4-4.3.2。
参考以上文件信息,在命令行中执行:
cd D:\src\kennethreitz-requests-969195a\
C:\Python27\python.exe setup.py install
cd D:\src\beautifulsoup4-4.3.2
C:\Python27\python.exe setup.py install
即可安装这两个第三方库。
如果以上步骤没有问题,那么此时已经具备执行此例中Python程序的运行环境了。
假设我的代码路径为D:\src\ZhihuHelper-master\,使用命令行窗口,执行命令:
cd D:\src\ZhihuHelper-master\
C:\Python27\python.exe answer.py -u 'user@zhihu.com' -p '123456' -b
即可备份登录用户的所有答案。注意,需要将'user@zhihu.com'与'123456'替换为相应知乎账号的登录邮箱与密码。若在上述最后一条命令中增加-d参数,将会删除该用户的所有回答,-b与-d参数可同时使用,将先备份答案,再执行删除操作。如果命令执行无误,将在D:\src\ZhihuHelper-master\中生成答案备份文件,文件名为
若是Mac OS用户,则无需执行上述的繁琐步骤。Mac OS自带Python运行环境,不过可能仍需安装Requests与BeautifulSoup依赖,不过方法较为简单,可参考以下步骤:
开启终端,执行命令:
easy_install requests
easy_install BeautifulSoup
安装完成后,使用Python程序的方法与上述类似。
-*- GNU/Linux用户不须说明。 -*-
==================================================================
以上步骤虽然看起来很繁琐,但Python项目的执行本可以更简单。无奈我是Python初学者啊!原谅我吧!
给自己挖了好大一个坑,终于填起来了。 我是来拆台的。。。
装Cygwin然后
curl <uri-of-the-python-script> | python
- 把代码下载到本地电脑:点击页面右侧的 Download Zip 即可
- 在本地配置 Python 环境,具体方法可以自行 Google
- 解压刚刚下载的 zip 文件,打开命令行,进入到这个目录,运行 python xxx.py。其中 xxx.py 是 Python 代码文件。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H
