Win10 安装 Python3 (上)
Python3 For Windows 10
installer
安装







随后可以看到,installer 在用户环境变量PATH中,添加了三项:

卸载
使用 installer 卸载 python 时,并不会移除 launcher。若要移除 launcher,需要打开“程序和功能”,在列表中选择删除。同时,python 也可以通过这里删除或修改。
简单配置
UTF-8 mode
两种方式:
- 设置环境变量 PYTHONUTF8 为 1;
- 在命令行中传递参数
-X utf8
即使该模式未开启,在下面两种情况下,仍将使用 UTF-8:
- Console I/O including standard I/O
- The filesystem encoding
Python Launcher
一个用于选择和执行不同版本 Python 的实用程序。
虚拟环境
如果没有显式给出 Python 版本,且激活了虚拟环境(由标准库 venv 模块或外部的 virtualenv 工具创建),那么 launcher 将使用虚拟环境中的解释器,而非全局的。
文件关联
.py, .pyw, .pyc
只有安装了 launcher,才会产生这些关联。这意味着,我们可以双击执行一个脚本文件,而不用打开命令行。
Shebang Lines
这个东西在 Nix 系统上是原生支持的,而在 Windows 上,由 launcher 来提供这一支持。
虽然很奇怪,但
#!/usr/bin/python
将启用默认的 Python 版本,当然,也可以显式地添加版本后缀,以启用其它版本。
使用 /usr/bin/env 形式的 shebang 将会在 PATH 中搜索 Python 可执行文件,其行为,就如同 Nix 中的 env 程序一样。
此外,也可以在 shebang 中向解释器传递一些选项。
Customization
INI
- 在
%appdata%(当前用户的应用数据目录)中的py.ini;(高优先级) - launcher 所在目录下的
py.ini。
Finding modules
Python 通常将它的库放在安装目录下,默认的库位于 {root}\Lib\,第三方库位于 {root}\Lib\site-packages\。
._pth 和 .pth 文件
pyvenv.cfg 文件
Pip
config
子命令:
- list
- edit
- 需要使用
--editor <editor>指定所用编辑器,否则使用变量 VISUAL 或 EDITOR 指定。 - 很奇怪的是,传入 VScode 的路径,总是报错,而使用 notepad 却没有问题。
- 需要使用
- get
- set
- unset
- debug
作用域选项:
| Options | Descriptions | Locations |
|---|---|---|
| --global | Use the system-wide configuration file only | C:\ProgramData\pip\pip.ini |
| --user | Use the user configuration file only | |
| --site | Use the current environment configuration file only |
file
位置
Per-user
- Default is
%appdata%\pip\pip.ini; - 由于历史原因,
%home%\pip\pip.ini也会被考虑; - 当然,也可以自定一个位置,设置环境变量
PIP_CONFIG_FILE即可。
Inside a virtualenv
%virtual_env%\pip.ini
Global
C:\ProgramData\pip\pip.ini
哪一个
如果发现有多个配置文件,那么按以下顺序进行读取,且后者覆盖前者:
- global
- per-user
- virtualenv-specific
怎么写
The names of the settings are derived from the long command line option, e.g. if you want to use a different package index (--index-url) and set the HTTP timeout (--default-timeout) to 60 seconds your config file would look like this:
[global]
timeout = 60
index-url = https://download.zope.org/ppix
Each subcommand can be configured optionally in its own section so that every global setting with the same name will be overridden; e.g. decreasing the timeout to 10 seconds when running the freeze (pip freeze) command and using 60 seconds for all other commands is possible with:
[global]
timeout = 60
[freeze]
timeout = 10
Boolean options like --ignore-installed or --no-dependencies can be set like this:
[install]
ignore-installed = true
no-dependencies = yes
To enable the boolean options --no-compile, --no-warn-script-location and --no-cache-dir, falsy values have to be used:
[global]
no-cache-dir = false
[install]
no-compile = no
no-warn-script-location = false
For options which can be repeated like --verbose and --quiet, a non-negative integer can be used to represent the level to be specified:
[global]
quiet = 0
verbose = 2
It is possible to append values to a section within a configuration file such as the pip.ini file. This is applicable to appending options like --find-links or --trusted-host, which can be written on multiple lines:
[global]
find-links =
http://download.example.com
[install]
find-links =
http://mirror1.example.com
http://mirror2.example.com
trusted-host =
mirror1.example.com
mirror2.example.com
This enables users to add additional values in the order of entry for such command line arguments.
环境变量
pip’s command line options can be set with environment variables using the format PIP_<UPPER_LONG_NAME> . Dashes (-) have to be replaced with underscores (_).
优先级
命令行参数>环境变量>配置文件
aboutMe
配置了一下镜像源:
> pip config --global set global.index-url https://mirrors.bfsu.edu.cn/pypi/web/simple
这将创建全局配置文件,并写入。
随后我直接在该文件中添加了一些配置项:
[global]
index-url = https://mirrors.bfsu.edu.cn/pypi/web/simple
cache-dir = D:\xxxxx\Documents\Python\pip\cache
注意,虽然看起来 cache-dir 像是和 cache 命令相关的,但实际上它是一个通用选项(General Options),而非 Cache Options,所以,如果将其放在 [cache] 下,将不会产生任何效果。
virtualenv
参考 Virtualenv
Creators
venv
可将创建行为委托给 Python 标准库中的 venv 模块。virtualenv 将创建一个进程来调用该模块,这在 Windows 上将是一笔不小的开销。
builtin
virtualenv 本身便可以执行创建操作。
Seeders
种包指的是 pip,setuptools,wheel 三者中的一或多个。安装种包,将使得你可以在创建的虚拟环境中安装其它的包。对于种包的安装,有两种机制:
pip
使用与 virtualenv 绑定的 pip 安装种包,这将创建一个进程来执行之。
add-data
在用户应用数据目录下创建一个安装镜像,随后要用到时,只需要简单的链接或拷贝这些镜像即可。对 Windows 来说,可能没有使能 symlink,但即便是拷贝,也快得多了。
可以使用环境变量 VIRTUALENV_OVERRIDE_APP_DATA 指定 the seed cache 的位置。
Activators
在虚拟环境目录下,Scripts文件夹中,有一些激活脚本。它们被用来修改 shell 的设置,以确保虚拟环境中的命令要优先于全局路径下的。
CLI interface
virtualenv 主要是一个命令行应用。默认的命令行标志可以被配置文件覆盖,而环境变量又优先于配置。使用 --help 时,可以在帮助信息的最后看到该标志的值,以及是否默认。
| Options | Default | Description |
|---|---|---|
| --app-data | 平台相关(win10 中为 %localappdata%\pypa\virtualenv |
a data folder used as cache by the virtualenv |
| --read-only-app-data | False | 以只读模式使用 app data 文件夹 |
| --reset-app-data | False | 移除 app data 文件夹(即使没有传递必需的 dest) |
| --upgrade-embed-wheels | False | 手动升级内置的 wheels(注意,这个不是特指用于种包的那个 wheel 包) |
| -p, --python | 安装时使用的 python 可执行版本 | 使用哪个 python 可执行文件来创建环境 |
| --creator | builtin if exist, else venv | 用于创建环境的执行者 |
| dest | 要在哪里创建 | |
| --clear | False | 如果目标目录不为空,清除之 |
| --no-vcs-ignore | False | 不要在目标目录下创建 VCS 忽略文件(如 .gitignore |
| --system-site-packages | False | 使得虚拟环境可以访问到全局的 site-packages |
| --symlinks | True | 可以 symlink,就不 copy |
| --copies, --always-copy | False | 总是 copy |
| --seeder | app-data | 种包的安装方式。若选择 pip,则很多选项将无意义 |
| --no-seed, --without-pip | False | 不安装种包 |
| --no-download, --never-download | True | 不要从 PyPI 上下载最新的种包 |
| --download | False | 从 PyPI 上下载最新的种包使用 |
| --pip, --setuptools, --wheel | bundle | 种的版本,默认为与 virtualenv 绑定的那个,否则使用指定的版本(所谓“绑定”,即为“内置”) |
| --no-pip, --no-setuptools, --no-wheel | False | 不安装种包 |
| --no-periodic-update | False | 不对内置的 wheels 进行周期性(14天)更新 |
| --symlink-app-data | False | 从 app data 中符号链接 python 包 |
| --activators | 全部 | 要生成哪些激活器:bash, batch, cshell, fish, powershell, python, xonsh |
| --prompt | (venv_name) | 为该环境指定一个提示符前缀 |
Configuration file
位置
和 pip 一样,virtualenv 也使用标准的 ini 格式的配置文件,默认为 %localappdata%\pypa\virtualenv\virtualenv.ini。
在 --help 输出的最后,可以看到配置文件的位置。可使用 VIRTUALENV_CONFIG_FILE 自定义其位置。
怎么写
基于命令行选项,将左边的 - 符号移除,使用 _ 替换 - 即可配置之。
aboutMe
[virtualenv]
app_data = D:\xxxxx\Documents\Python\pypa\virtualenv
no_vcs_ignore = true
system_site_packages = true
no_periodic_update = true
activators = batch
Misc
- venv — Creation of virtual environments
Note: While symlinks are supported on Windows, they are not recommended. Of particular note is that double-clicking
python.exein File Explorer will resolve the symlink eagerly and ignore the virtual environment.
The created pyvenv.cfg file also includes the include-system-site-packages key, set to true if venv is run with the --system-site-packages option, false otherwise.
When a virtual environment is active, the VIRTUAL_ENV environment variable is set to the path of the virtual environment. This can be used to check if one is running inside a virtual environment.
... However, all scripts installed in a virtual environment should be runnable without activating it, and run with the virtual environment’s Python automatically.
Note: A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments, and (by default) any libraries installed in a “system” Python, i.e., one which is installed as part of your operating system.
A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment.
Common installation tools such as setuptools and pip work as expected with virtual environments. In other words, when a virtual environment is active, they install Python packages into the virtual environment without needing to be told to do so explicitly.
When a virtual environment is active (i.e., the virtual environment’s Python interpreter is running), the attributes
sys.prefixandsys.exec_prefixpoint to the base directory of the virtual environment, whereassys.base_prefixandsys.base_exec_prefixpoint to the non-virtual environment Python installation which was used to create the virtual environment. If a virtual environment is not active, thensys.prefixis the same assys.base_prefixandsys.exec_prefixis the same assys.base_exec_prefix(they all point to a non-virtual environment Python installation).When a virtual environment is active, any options that change the installation path will be ignored from all
distutilsconfiguration files to prevent projects being inadvertently installed outside of the virtual environment.When working in a command shell, users can make a virtual environment active by running an
activatescript in the virtual environment’s executables directory (the precise filename and command to use the file is shell-dependent), which prepends the virtual environment’s directory for executables to thePATHenvironment variable for the running shell. There should be no need in other circumstances to activate a virtual environment; scripts installed into virtual environments have a “shebang” line which points to the virtual environment’s Python interpreter. This means that the script will run with that interpreter regardless of the value ofPATH. On Windows, “shebang” line processing is supported if you have the Python Launcher for Windows installed (this was added to Python in 3.3 - see PEP 397 for more details). Thus, double-clicking an installed script in a Windows Explorer window should run the script with the correct interpreter without there needing to be any reference to its virtual environment inPATH.
Win10 安装 Python3 (上)的更多相关文章
- WIN10安装不上IIS,使用IISExpress作为发布服务
[背景] 本人开发Win程序,需要调用网站资源作为Win程序的辅助功能,为此需要本地开发环境支持IIS.最近重装系统,VS安装完后,接着再安装IIS,可以在添加删除程序中反复尝试,均告安装失败提示.最 ...
- 【转】Win10下python3和python2多版本同时安装并解决pip共存问题
[转]Win10下python3和python2多版本同时安装并解决pip共存问题 特别说明,本文是在Windows64位系统下进行的,32位系统请下载相应版本的安装包,安装方法类似. 使用pytho ...
- Win10 安装 Anaconda3 用 Anaconda3 安装TensorFlow 1.2 (只支持python3.5)
Win10 安装 Anaconda3 1.安装Anaconda3 选择相应的Anaconda进行安装,下载地址点击这里,下载对应系统版本的Anaconda,官网现在的版本是Anaconda 4.3.1 ...
- python环境搭建-在Windows上安装python3.5.2
在Windows上安装Python3.5.2 首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Python 3.5.2对应的64位安装程序或32位安装程序(网速慢的同学 ...
- 在Linux上安装Python3
1. 安装依赖环境 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline- ...
- 在CentOS上安装Python3的三种方法
Centos7默认自带了Python2.7版本,但是因为项目需要使用Python3.x你可以按照此文的三个方法进行安装. 注:本文示例安装版本为Python3.5, 一.Python源代码编译安装 安 ...
- centos7.4上安装python3环境的坑
前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...
- 如何在CentOS7上安装Python3及对应问题
首先一般来说安装好的CentOS是会自带python2.7,但是是没有安装python3的环境的 [root@host bin]# pwd /usr/bin [root@host bin]# ls p ...
- 解决在Mac上用pyenv安装python3失败的问题
背景 前段时间在本地Mac系统上要跑一个python3写的压测脚本. Mac默认安装的是python2, 而且很多软件依赖的也是python2. 为了不影响现有系统其它软件, 当时安装了pyenv来实 ...
随机推荐
- Day11_54_泛型(Generic)
泛型 * Java泛型设计原则:只要在编译时期没有出现警告,那么运行时期就不会出现ClassCastException异常. * 泛型:把类型明确的工作推迟到创建对象或调用方法的时候才去明确的特殊的类 ...
- Python基础之容易忘记的地方
(1)编译型与解释型语言区别: 编译型:一次性,把所有代码编译成机器能识别的二进制码,再运行 代表语言:c,c++ 优点: 执行速度块 缺点: 开发速度慢,调试周期长 解释型:代码从上到下一行一行解释 ...
- 概A第二章测试
以下判断题全是(√) 问题 1 得 10 分,满分 10 分 问题 2 得 10 分,满分 10 分 0-1分布相当于一个特殊的二项分布b(1,p) ...
- Linux下部署Django项目
目录 安装python3.X环境 安装部署开启django 由于Linux系统默认自带的是2.X环境,所以我们需要去安装3.X环境的python. 安装python3.X环境 1.使用下面的命令下载P ...
- APP的编译和反编译
目录 Apktool的准备 Apktool解压APP Apktool打包APP 对APP进行签名
- WIN64内核编程-的基础知识
WIN64内核编程基础班(作者:胡文亮) https://www.dbgpro.com/x64driver 我们先从一份"简历"说起: 姓名:X86或80x86 性别:? 出生 ...
- 【JavaScript】【dp】Leetcode每日一题-解码方法
[JavaScript]Leetcode每日一题-解码方法 [题目描述] 一条包含字母 A-Z 的消息通过以下映射进行了 编码 : 'A' -> 1 'B' -> 2 ... 'Z' -& ...
- ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule
解释:执行docker-compose up -d时出现ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule 原因:防火墙 ...
- 数据库增量日志监听canal
概述 canal是阿里巴巴旗下的一款开源项目,纯Java开发.基于数据库增量日志解析,提供增量数据订阅&消费,目前主要支持了MySQL(也支持mariaDB). 起源:早期,阿里巴巴B2B公司 ...
- 使用FastDFS进行文件管理
使用FastDFS进行文件管理 FastDFS简介 FastDFS: FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等, ...