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来实 ...
随机推荐
- 关于搭建FTP服务器
首先我们创建一个用户账户用于登录FTP进行操作.右键点击桌面的我的点击选择管理选项,进入管理界面打开本地用户和组选项,我们可以看到列表中的用户选项 2 然后右键用户选项,在下拉菜单中选择新用户,开始建 ...
- 一.文件处理和json模块(容易混淆知识点即用法)
一.文件处理 注意点1: 打开文件包含两部分资源:操作系统级打开得文件+应用程序的变量. 在操作完毕一个文件时,必须把该文件的两部分资源一个不落的回收 如下: f.close() #回收操作系统级打开 ...
- 如何识别自己基因组数据是哪个全基因组参考版本(Genome Reference Versions/ Genome Build)
首先在这里先感谢我们[Bio生信学习交流群]的群友和创建此群的群主[陈博士后]. 今天解决的问题是怎么查看自己的基因组数据是哪个Genome Reference Versions. 步骤: 第一步,打 ...
- 如何使用natapp来实现内网穿透及案例
1. 业务场景 当我们的项目是部署在本地的时候,如何让其他用户(不在同一个局域网之下)来进行调用呢?这时我们就可以使用内网穿透将自己的IP通过映射成相应的地址,然后再通过映射后的地址来进行访问本地的项 ...
- Spring Cloud & Alibaba 实战 | 第十二篇: 微服务整合Sentinel的流控、熔断降级,赋能拥有降级功能的Feign新技能熔断,实现熔断降级双剑合璧(JMeter模拟测试)
目录 一. Sentinel概念 1. 什么是Sentinel? 2. Sentinel功能特性 3. Sentinel VS Hystrix 二. Docker部署Sentinel Dashboar ...
- grafana接入zabbix数据源
一.grafana介绍 grafana是开源免费的应用数据可视化仪表盘,由于zabbix本身对监控数据可视化并不侧重,所以大多使用第三方数据可视化工具来做大屏.下面向小伙伴们介绍grafana接入za ...
- 1026 Table Tennis
A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For a ...
- hdu4267线段树段更新,点查找,55棵线段树.
题意: 给你N个数,q组操作,操作有两种,查询和改变,查询就是查询当前的这个数上有多少,更改是给你a b k c,每次从a到b,每隔k的数更改一次,之间的数不更改,就相当于跳着更新. 思路: ...
- LA3602DNA序列
题意: 给你一个一些DNA序列(只有ACGT)然后让你构造一个序列,使得所有的序列到他的Hamming距离最小,所有的序列包括构造的序列长度都是N,Hamming表示两个序列的不同字符位置个 ...
- PowerShell-5.网络请求
写了一个函数,用于文件下载并且执行: function DownLoadAndRun($vUrl ,$vLocalPath ,$vStart){ Import-Module BitsTransfer ...