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来实 ...
随机推荐
- Linux下查看CPU、内存占用率
linux下查看最消耗CPU.内存的进程 CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 内存消耗最多的前10个进程: ps ...
- TP5 验证-内置规则
系统内置的验证规则如下: 格式验证类 require 验证某个字段必须,例如: 'name'=>'require' number 或者 integer 验证某个字段的值是否为数字(采用filte ...
- Python中zipfile压缩文件模块的使用
目录 zipfile 压缩一个文件 解压文件 高级应用 利用 zipfile 模块破解压缩文件口令:Python脚本破解压缩文件口令 zipfile Python 中 zipfile 模块提供了对 z ...
- 模板templates的使用
目录 模板及其渲染 模板查找路径 DTL模板语法 常用的模板标签 DTL常用过滤器 模块结构优化 加载静态文件 模板及其渲染 视图函数只是直接返回文本,而在实际生产环境中其实很少这样用,因为实际的页面 ...
- Windows PE变形练手1-用PE自己的机器码修改自己的逻辑
PE变形练手1-用PE自己的机器码修改自己的逻辑 就是找一个PE文件,用自己的部分代码部分覆盖或者而修改自己另一个代码部分的补丁姿势(现实中使用很少,极少数破解可以用到.这次例子目的是了解PE). 第 ...
- 神经网络与机器学习 笔记—卷积神经网络(CNN)
卷积神经网络 之前的一些都是考虑多层感知器算法设计相关的问题,这次是说一个多层感知器结构布局相关的问题.来总结卷积神经网络.对于模式分类非常合适.网络的提出所隐含的思想收到了神经生物学的启发. 第一个 ...
- ajax提交session超时跳转页面使用全局的方法来处理
来自:http://www.jb51.net/article/43770.htm 如果是ajax提交,超时时从服务器发出的跳转命令就不会起作用,所以如果是session超时,而且是在ajax请求,就在 ...
- PowerDesigner16安装和使用
安装 安装参考链接:PowerDesigner安装教程 因为这个博主已经操作的很详细了,这边就不做过多的赘述. 使用 新建模型 选择物理模型 调出面板Palette 建表 最终的效果(一般不在数据库层 ...
- Mybatis-Plus03 代码自动生成器
先看完Mybatis-Plus01和Mybatis-Plus02再看Mybatis-Plus03 AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerato ...
- Asp.NetCore Web开发之会话技术
这节讲一下会话技术,首先了解一下什么是会话,会话是指浏览器打开到关闭的过程中,多次与服务器发送接收数据的过程. 由于HTTP是无状态协议,一次请求响应过后,产生的数据就随之释放了,可是在某些情况下,我 ...