该文章是对youtube-dl 项目README.md文件的翻译,项目地址:https://github.com/ytdl-org/youtube-dl/blob/master/README.md#readme

当前版本:v2019.03.18


youtube-dl - 从youtube.com或其他视频平台下载视频

安装

立即为所有UNIX用户安装 (如Linux, macOS, 等),输入:

1
2
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

如果你没有curl工具, 你也可以使用相近的wget工具:

1
2
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

Windows用户可以 下载exe文件 并且放在除了%SYSTEMROOT%\System32以外任何的PATH 位置 (例如:不要 放在 C:\Windows\System32).

你也可以通过pip安装:

1
sudo -H pip install --upgrade youtube-dl

如果你早已安装youtube-dl,该命令行将会更新它。想获取更多信息,请参阅 pypi page

macOS用户可以通过Homebrew工具来安装youtube-dl:

1
brew install youtube-dl

或则使用 MacPorts工具:

1
sudo port install youtube-dl

此外,参考 开发者向导 来查看如何使用git仓库。 想获取包括PGP签名的更多选项,请参阅youtube-dl 下载界面

描述

youtube-dl是一款命令行工具,可以从YouTube.com和一些其他站点下载视频。它依赖于Python解释器,解释器版本要求为 2.6, 2.7, 或者 3.2+,并不限制于特定平台。它应该可以运行在类Unix,Windows和macOS平台上。其被发布于公共域, 意味着你可以修改、重新分发、或凭个人意愿使用它。

1
youtube-dl [OPTIONS] URL [URL...]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-h, --help						打印帮助文档并退出
--version 打印程序版本信息并退出
-U, --update 更新程序至最新版本,需保证拥有足够权限(如需可使用sudo命令)
-i, --ignore-errors 当下载错误时继续,例如在播放列表跳过不可获取视频
--abort-on-error 当下载错误时停止下载其他视频(例如在播放列表和命令行)
--dump-user-agent 展示当前浏览器标识
--list-extractors 列出所有的提取器
--extractor-descriptions 输出所有支持的提取器描述
--force-generic-extractor 强制使用通用提取器
--default-search PREFIX 使用前缀补全不完整的URLs。例如“gvsearch2:”利用youtube-dl从google视频中下载两个有关“大苹果”的视频,使用"auto"参数让youtube-dl自行猜一个(猜测时,"auto_warning"将会抛出)。"error"参数就会抛出错误。默认值"fixup_error"会修复不完整URLs,如果不是搜索相关就无法实现,会抛出错误。
--ignore-config 当使用全局配置文件/etc/youtube-dl.conf时,不再读取用户的配置文件~/.config/youtube-dl/config(Windows下为%APPDATA%/youtube-dl/config.txt)
--config-location PATH 配置文件的配置,既可以是配置文件的路径或包含其的目录
--flat-playlist 仅列出视频列表而不下载
--mark-watched 标记看过此视频(仅对YouTube)
--no-mark-watched 不标记看过此视频(仅对YouTube)
--no-color 对屏幕输出结果不上色

网络选项:

1
2
3
4
5
--proxy URL						使用HTTP/HTTPS/SOCKS代理。需指定一个具体的协议,例如:socks5://127.0.0.1:1080/。传入空字段(--proxy "")将会直连
--socket-timeout SECONDS 放弃连接前的等待时间,秒为单位
--source-address IP 绑定客户端的IP地址
-4, --force-ipv4 所有连接强制走IPv4协议
-6, --force-ipv6 所有连接强制走IPv6协议

地区限制:

1
2
3
4
5
--geo-verification-proxy URL	在一些地区限制网址使用代理IP地址。由--proxy指定的默认代理(如果该选项不存在,则为none)用于实际下载。
--geo-bypass 通过伪装HTTP头:X-Forwarded-For 来绕过地区限制
--no-geo-bypass 不用伪装HTTP头:X-Forwarded-For 来绕过地区限制
--geo-bypass-country CODE 利用提供具体的双字母ISO 3166-2国别码强制绕过地区限制
--geo-bypass-ip-block IP_BLOCK 使用CIDR表示法中明确提供的IP块强制绕过地理限制

视频选择:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--playlist-start NUMBER			播放列表中从第几个开始下载(默认是1)
--playlist-end NUMBER 播放列表中到第几个结束下载(默认最后一个)
--playlist-items ITEM_SPEC 指定列表中要下载的视频项目编号。如:"--playlist-items 1,2,5,8""--playlist-items 1-3,7,10-13"
--match-title REGEX 下载标题匹配的视频(可用正则表达式或区分大小写的子字符串)
--reject-title REGEX 跳过下载标题匹配的视频(可用正则表达式或区分大小写的子字符串)
--max-downloads NUMBER 下载NUMBER个文件后中止
--min-filesize SIZE 不下载小于SIZE的视频(例如:50k或44.6m)
--max-filesize SIZE 不下载大于SIZE的视频(例如:50k或44.6m)
--date DATE 仅下载指定上传日期的视频
--datebefore DATE 仅下载指定上传日期或之前的视频
--dateafter DATE 仅下载指定上传日期或之后的视频
--min-views COUNT 不下载观看次数小于COUNT的视频
--max-views COUNT 不下载观看次数大于COUNT的视频
--match-filter FILTER 通用视频过滤器。可指定任何键(有关可用key列表,请参阅“OUTPUT TEMPLATE”)!key检查密钥是否不存在,key>NUMBER(如“comment_count> 12”,也适用于> =,<,<=,!=,=) 比较一个数字,key ='LITERAL'(比如“uploader ='Mike Smith',也适用于!=)来匹配字符串文字可用&实现多个匹配。 除非您在参数后加问号(?),否则将排除未知的值。例如,要仅匹配已liked超过100次并且disliked不到50次的视频(或者在给定视频中不可用的不喜欢功能)并且有视频描述,请使用--match-filter "like_count > 100&dislike_count <? 50 & description"
--no-playlist 如果URL指向视频和播放列表,则仅下载视频
--yes-playlist 如果URL指向视频和播放列表,则仅下载播放列表
--age-limit YEARS 仅下载适合特定年龄的视频
--download-archive FILE 仅下载存档文件中未列出的视频。记录下载所有视频的ID。
--include-ads 下载时同时下载广告(实验性功能)

下载选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-r, --limit-rate RATE			最大下载速率(bps)(例如 50K 或 4.2M)
-R, --retries RETRIES 重试次数。(默认10,可选 "infinite"
--fragment-retries RETRIES 片段重试次数(默认10),可选 "infinite")(DASH, hlsnative and ISM)
--skip-unavailable-fragments 跳过不可用片段 (DASH, hlsnative and ISM)
--abort-on-unavailable-fragment 当片段不可获取时,中断下载
--keep-fragments 下载完成后,将下载的片段保存在磁盘上; 片段默认被删除
--buffer-size SIZE 下载缓存大小(例如 1024 或 16K)(默认 1024)
--no-resize-buffer 不自动调整缓存大小。默认情况下,缓存大小会基于初始大小自动调整
--http-chunk-size SIZE 基于块的HTTP下载的块的大小(例如10485760或10M)(默认为禁用)。 可能有助于绕过网络服务器强加的带宽限制(实验性功能)
--playlist-reverse 逆序下载视频列表
--playlist-random 随机顺序下载视频列表
--xattr-set-filesize 设定xattribute ytdl文件大小
--hls-prefer-native 使用原生HLS代替ffmpeg进行下载
--hls-prefer-ffmpeg 使用ffmpeg代替原生HLS进行下载
--hls-use-mpegts 使用mpegts容器获取HLS视频,允许在下载时播放视频(某些播放器可能无法播放)
--external-downloader COMMAND 使用指定的外部下载程序。目前支持aria2c,avconv,axel,curl,ffmpeg,httpie,wget
--external-downloader-args ARGS 为外部下载器指定参数

文件系统选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-a, --batch-file FILE            File containing URLs to download ('-' for
stdin), one URL per line. Lines starting
with '#', ';' or ']' are considered as
comments and ignored.
--id Use only video ID in file name
-o, --output TEMPLATE Output filename template, see the "OUTPUT
TEMPLATE" for all the info
--autonumber-start NUMBER Specify the start value for %(autonumber)s
(default is 1)
--restrict-filenames Restrict filenames to only ASCII
characters, and avoid "&" and spaces in
filenames
-w, --no-overwrites Do not overwrite files
-c, --continue Force resume of partially downloaded files.
By default, youtube-dl will resume
downloads if possible.
--no-continue Do not resume partially downloaded files
(restart from beginning)
--no-part Do not use .part files - write directly
into output file
--no-mtime Do not use the Last-modified header to set
the file modification time
--write-description Write video description to a .description
file
--write-info-json Write video metadata to a .info.json file
--write-annotations Write video annotations to a
.annotations.xml file
--load-info-json FILE JSON file containing the video information
(created with the "--write-info-json"
option)
--cookies FILE File to read cookies from and dump cookie
jar in
--cache-dir DIR Location in the filesystem where youtube-dl
can store some downloaded information
permanently. By default
$XDG_CACHE_HOME/youtube-dl or
~/.cache/youtube-dl . At the moment, only
YouTube player files (for videos with
obfuscated signatures) are cached, but that
may change.
--no-cache-dir Disable filesystem caching
--rm-cache-dir Delete all filesystem cache files

Thumbnail images:

1
2
3
4
--write-thumbnail                Write thumbnail image to disk
--write-all-thumbnails Write all thumbnail image formats to disk
--list-thumbnails Simulate and list all available thumbnail
formats

Verbosity / Simulation Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-q, --quiet                      Activate quiet mode
--no-warnings Ignore warnings
-s, --simulate Do not download the video and do not write
anything to disk
--skip-download Do not download the video
-g, --get-url Simulate, quiet but print URL
-e, --get-title Simulate, quiet but print title
--get-id Simulate, quiet but print id
--get-thumbnail Simulate, quiet but print thumbnail URL
--get-description Simulate, quiet but print video description
--get-duration Simulate, quiet but print video length
--get-filename Simulate, quiet but print output filename
--get-format Simulate, quiet but print output format
-j, --dump-json Simulate, quiet but print JSON information.
See the "OUTPUT TEMPLATE" for a description
of available keys.
-J, --dump-single-json Simulate, quiet but print JSON information
for each command-line argument. If the URL
refers to a playlist, dump the whole
playlist information in a single line.
--print-json Be quiet and print the video information as
JSON (video is still being downloaded).
--newline Output progress bar as new lines
--no-progress Do not print progress bar
--console-title Display progress in console titlebar
-v, --verbose Print various debugging information
--dump-pages Print downloaded pages encoded using base64
to debug problems (very verbose)
--write-pages Write downloaded intermediary pages to
files in the current directory to debug
problems
--print-traffic Display sent and read HTTP traffic
-C, --call-home Contact the youtube-dl server for debugging
--no-call-home Do NOT contact the youtube-dl server for
debugging

Workarounds:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--encoding ENCODING              Force the specified encoding (experimental)
--no-check-certificate Suppress HTTPS certificate validation
--prefer-insecure Use an unencrypted connection to retrieve
information about the video. (Currently
supported only for YouTube)
--user-agent UA Specify a custom user agent
--referer URL Specify a custom referer, use if the video
access is restricted to one domain
--add-header FIELD:VALUE Specify a custom HTTP header and its value,
separated by a colon ':'. You can use this
option multiple times
--bidi-workaround Work around terminals that lack
bidirectional text support. Requires bidiv
or fribidi executable in PATH
--sleep-interval SECONDS Number of seconds to sleep before each
download when used alone or a lower bound
of a range for randomized sleep before each
download (minimum possible number of
seconds to sleep) when used along with
--max-sleep-interval.
--max-sleep-interval SECONDS Upper bound of a range for randomized sleep
before each download (maximum possible
number of seconds to sleep). Must only be
used along with --min-sleep-interval.

Video Format Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
-f, --format FORMAT              Video format code, see the "FORMAT
SELECTION" for all the info
--all-formats Download all available video formats
--prefer-free-formats Prefer free video formats unless a specific
one is requested
-F, --list-formats List all available formats of requested
videos
--youtube-skip-dash-manifest Do not download the DASH manifests and
related data on YouTube videos
--merge-output-format FORMAT If a merge is required (e.g.
bestvideo+bestaudio), output to given
container format. One of mkv, mp4, ogg,
webm, flv. Ignored if no merge is required

Subtitle Options:

1
2
3
4
5
6
7
8
9
10
11
12
--write-sub                      Write subtitle file
--write-auto-sub Write automatically generated subtitle file
(YouTube only)
--all-subs Download all the available subtitles of the
video
--list-subs List all available subtitles for the video
--sub-format FORMAT Subtitle format, accepts formats
preference, for example: "srt" or
"ass/srt/best"
--sub-lang LANGS Languages of the subtitles to download
(optional) separated by commas, use --list-
subs for available language tags

Authentication Options:

1
2
3
4
5
6
-u, --username USERNAME          Login with this account ID
-p, --password PASSWORD Account password. If this option is left
out, youtube-dl will ask interactively.
-2, --twofactor TWOFACTOR Two-factor authentication code
-n, --netrc Use .netrc authentication data
--video-password PASSWORD Video password (vimeo, smotri, youku)

Adobe Pass Options:

1
2
3
4
5
6
7
8
9
--ap-mso MSO                     Adobe Pass multiple-system operator (TV
provider) identifier, use --ap-list-mso for
a list of available MSOs
--ap-username USERNAME Multiple-system operator account login
--ap-password PASSWORD Multiple-system operator account password.
If this option is left out, youtube-dl will
ask interactively.
--ap-list-mso List all supported multiple-system
operators

Post-processing Options:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-x, --extract-audio              Convert video files to audio-only files
(requires ffmpeg or avconv and ffprobe or
avprobe)
--audio-format FORMAT Specify audio format: "best", "aac",
"flac", "mp3", "m4a", "opus", "vorbis", or
"wav"; "best" by default; No effect without
-x
--audio-quality QUALITY Specify ffmpeg/avconv audio quality, insert
a value between 0 (better) and 9 (worse)
for VBR or a specific bitrate like 128K
(default 5)
--recode-video FORMAT Encode the video to another format if
necessary (currently supported:
mp4|flv|ogg|webm|mkv|avi)
--postprocessor-args ARGS Give these arguments to the postprocessor
-k, --keep-video Keep the video file on disk after the post-
processing; the video is erased by default
--no-post-overwrites Do not overwrite post-processed files; the
post-processed files are overwritten by
default
--embed-subs Embed subtitles in the video (only for mp4,
webm and mkv videos)
--embed-thumbnail Embed thumbnail in the audio as cover art
--add-metadata Write metadata to the video file
--metadata-from-title FORMAT Parse additional metadata like song title /
artist from the video title. The format
syntax is the same as --output. Regular
expression with named capture groups may
also be used. The parsed parameters replace
existing values. Example: --metadata-from-
title "%(artist)s - %(title)s" matches a
title like "Coldplay - Paradise". Example
(regex): --metadata-from-title
"(?P<artist>.+?) - (?P<title>.+)"
--xattrs Write metadata to the video file's xattrs
(using dublin core and xdg standards)
--fixup POLICY Automatically correct known faults of the
file. One of never (do nothing), warn (only
emit a warning), detect_or_warn (the
default; fix file if we can, warn
otherwise)
--prefer-avconv Prefer avconv over ffmpeg for running the
postprocessors
--prefer-ffmpeg Prefer ffmpeg over avconv for running the
postprocessors (default)
--ffmpeg-location PATH Location of the ffmpeg/avconv binary;
either the path to the binary or its
containing directory.
--exec CMD Execute a command on the file after
downloading, similar to find's -exec
syntax. Example: --exec 'adb push {}
/sdcard/Music/ && rm {}'
--convert-subs FORMAT Convert the subtitles to other format
(currently supported: srt|ass|vtt|lrc)

背景

个人以前博客常挂在自建的基于dockerWordPress平台,但往日学艺不精,对docker操作陌生,都是基于别人的模板快速搭建;尽近两年来,经历了多次迁移:

  • 腾讯云(centOS) → 阿里云(ubuntu) → DigitalOcean(ubuntu)

同时也经过了多次的版本升级,且前期多是在wordpress内置的编辑器中编写,也尝试过百度UEditor编辑器

,最终转到MarkDown编辑器。除此外,图床也一变再变,过程中多次忘记备份,导致存在一些图片缺失。

回想写博客的本质,是为了记录心路,学习知识。实在不应该放过多时间在博客建设本身😢。

思前想后,还是准备把博客落脚在GitHub Page,不用去考虑数据库、cdn等,仅采用静态页面,一篇文章也为一份md文件,图床部分也不去用七牛等服务商,就是oneDrive的分享,简单直接。写博客也应该像提交代码一样,commit + push😉。

大致步骤如下:

GitHub建立固定格式仓库

登录GitHub,新建一个仓库,在Repository name中输入新建仓库的名称,我们现在是要搭建自己的个人博客,Repository name是有固定格式的:name.github.io,其中name可以随便填,一般是用自己的名字,点击Create Repository。

配置Git

安装Git

Git下载地址,选择适合版本,默认安装即可,安装后git相关命令会自动添加到系统path。可通过:

1
git --version

来确认。

配置Git

为了把本地的仓库中的内容传输到GitHub上,需要配置ssh key,无论是上传自己的博客还是上传其他的仓库都需要连接Github,ssh key是一个token,作用是身份验证。 为了在本地创建ssh key,打开Git Bash,输入命令:

1
ssh-keygen -t rsa -C "email"  # email是我们在注册Github时使用的邮箱

输入上面的命令后按Enter键,Git Bash会提示:

1
Enter file in which to save the key (/c/Users/sun/.ssh/id_rsa):_

直接按Enter,Git Bash会在默认路径C:.ssh下生成几个文件。

然后Git Bash又给出提示:

1
Enter passphrase <empty for no passphrase>:_

这是在提示我们输入密码,直接回车表示不设置密码;此处我不设置密码,然后Git Bash要求我们重复密码,也直接回车,然后就会提示ssh key已经生成。

  1. 点击Settings;

  2. 在页面左侧找到Deploy keys并点击;

  3. 点击右侧的Add deploy key按钮,title随意填,Key填写ssh key文件中复制的key(包括ssh-ras头);

  4. 点击Add Key,保存ssh key。

我们需在本地验证ssh key设置是否成功,打开cmd,输入命令:

1
ssh -T git@github.com

若看到

1
You’ve successfully authenticated, but GitHub does not provide shell access

表示当前已经成功地连接上了自己的GitHub账户

接下来,设置一下自己的用户名和邮箱

1
2
git config --global user.name "my_github_name"
git config --global user.email "my_github_email"

至此,我们已经成功地将个人电脑和Github账号连接。

安装node.js 和 hexo

安装node.js

node.js下载地址

按照需要选择不同的版本,下载到本地之后,直接双击安装,一路默认即可,node.js安装后,会自动配置环境变量,打开windows的控制台,输入命令:

1
node -v

安装Hexo

hexo项目须在电脑的磁盘里新建一个空文件夹,在我的电脑上是*C:_next*,用于存放本地仓库,和Github上的xxxxx.github.io是对应的,下面以命令行为例,完成Hexo安装

1
2
3
mkdir C:\Users\smile\hexo_next   # 新建文件夹
cd C:\Users\smile\hexo_next
npm install hexo -g # 安装Hexo,-g代表全局安装

安装耗时较长,最终可通过

1
hexo -v

检测安装

搭建本地测试环境

初始化*C:_next*这个文件夹,打开Git Bash进入此目录,输入命令:

1
2
3
4
hexo init
npm install # 安装Hexo所需要的组件
hexo g # 产生webapp文件
hexo s # 开启服务器

此时控制台提示:

1
2
3
4
5
6
7
8
9
INFO  Start processing
WARN ===============================================================
WARN ========================= ATTENTION! ==========================
WARN ===============================================================
WARN NexT repository is moving here: https://github.com/theme-next
WARN ===============================================================
WARN It's rebase to v6.0.0 and future maintenance will resume there
WARN ===============================================================
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

表明启动成功

使用next设计个性化博客

将Hexo的主题切换为NexT

进入到*C:_next*文件夹,打开cmd

1
git clone https://github.com/theme-next/hexo-theme-next themes/next

打开C:_next\_config.yml

把theme: lansscape改为theme: next

切换Next主题

进入C:_next,打开NexT的配置文件_config.yml,选择自己喜欢的主题样式,选择哪个样式就需要把主题前面的#去掉

设置动态背景

在*C:_next\_config.yml*中,canvas_nest设置成ture,并且可选多种动态背景

取消侧边栏目录的自动编号

在*C:_next\_config.yml*中,修改toc下number属性为false

在右上角或者左上角实现fork me on github

GitHub RibbonsGitHub Corners选择自己喜欢的挂饰,拷贝方框内的代码

将复制的代码放到C:_next_layout.swig文件中,放在

1
<div class="headband"></div>

后面,如下图

实现文章字数统计和阅读时长功能

1
npm install hexo-wordcount --save

编辑*C:_next\_config.yml*,找到post_wordcount,将所有的false都改为true:

Hexo博客添加站内搜索

需要安装 hexo-generator-search,输入命令:

1
npm install hexo-generator-search --save

安装 hexo-generator-searchdb,输入命令:

1
npm install hexo-generator-searchdb --save

编辑*C:_next\_config.yml*,找到Local search,做如下设置:

效果如下:

连接Hexo和Github Pages及部署博客

接下来就是将Hexo与GitHub Pages连接起来 打开*C:_next\_config.yml*文件,找到deploy字段,改为如下内容

1
2
3
4
deploy:
type: git
repository: git@github.com:user_name/respname.github.io.git
branch: master

填写GitHub的用户名 和 博客仓库名,如下图所示

在产生webapp应用和部署到GitHub之前,需要安装一个扩展插件,在C:_next中打开cmd,输入命令:

1
npm install hexo-deployer-git --save

使用命令:

1
hexo clean & hexo d -g  # hexo g 生成webapp应用  # hexo d 部署

就可以发布到GitHub上啦!😉

第十九周

课程 日期 时间
微机原理 1月8号 13:30 - 15:10
计算机网络技术 1月9号 13:30 - 15:10
数字信号处理 1月10号 8:00 - 9:40
毛概 1月10号 10:20 - 12:00
通信原理 1月11号 15:50 - 17:30

存在这样一种情况,经常在非服务器环境下开发python程序,即使在本地运行良好,但是在服务器的环境下就会存在问题,如何保证开发环境跟运行环境一致呢?

这里通过PyCharm远程解释器加上自动文件同步功能,实现

  • 本地编译 -> 同步到服务器 -> 远程debug

的方式来调试程序。

远程服务器的同步配置

局域网下的服务器IP地址为: 192.168.2.192,python版本3.6, 且在项目下已有虚拟环境,开启ssh服务。

首先我们需要配置PyCharm通服务器的代码同步,打开Tools | Deployment | Configuration

点击左边的“+”添加一个部署配置,输入名字,类型选SFTP

确定之后,再配置远程服务器的ip、端口、用户名和密码。root path是文件上传的根目录,注意这个目录必须用户名有权限创建文件。

然后配置映射,local path是你的工程目录,就是需要将本地这个目录同步到服务器上面,我填的是项目根目录。 Deploy path on server 这里填写相对于root path的目录,下面那个web path不用管先

还有一个设置,打开Tools | Deployment | Options,将”Create Empty directories”打上勾,要是指定的文件夹不存在,会自动创建。

上传和下载文件

有几种方法可以实现本地和远程文件的同步,手动和当文件保存后自动触发。这里我选中Automatic upload

手动上传方式很简单,选择需要同步的文件或文件夹,然后选择 Tools | Deployment | Upload to sftp(这个是刚刚配置的部署名称)

如果在服务器存在已有项目,选择Compare with … ,然后全部接受服务器端的文件。

比较远程和本地文件

有时候你并不确定远程和本地版本的完全一致,需要去比较看看。PyCharm提供了对比视图来为你解决这个问题。

选择Tools | Deployment | Browse Remote Host,打开远程文件视图,在右侧窗口就能看到远程主机中的文件

选择一个你想要对比的文件夹,点击右键->Sync with Local,打开同步对比窗口,使用左右箭头来同步内容。

配置远程Python解释器

新建一个python解释器,选择SSH 解释器,由于我上面配置过就直接选模板, 这里请仔细看我的Python解释器是虚拟环境virtualenv,这个要在服务器上面先创建好虚拟环境。

配置Django运行参数

指定启动Host0.0.0.0,表示允许所有ip进行调试 若需要启动web浏览器,指定下地址为服务器端的ip

0%