目录
1,安装 (有人说pip install jupyter 也好用,没试过,但是下面的好使 亲测)
查找当前解释器位置:使用代码查找进入Prompt给窗口激活我的环境输入代码查找
Linux的激活:
source activate python2_omgtools
为什么要虚拟环境以及什么是虚拟环境?
创建环境
下面是我自己使用anaconda在windows上配置的虚拟环境。就两条语句:
conda create -n first_name python=3.6 # 创建 其中 first_name 是我使用的名字,激活的时候也使用这个名字
conda activate first_name # 激活
问题:创建的python好像只是从官网上的特别干净的python 连numpy包都没有装,但是内置的包math os等都有,就是纯的python呵呵了。没关系,用什么包自己就装什么包吧!
关键货:使用pycharm或者jupter写代码怎么办?
既然是一个全新的python环境,我想那么应该有一个新的解释器吧!!这个解释器一定不是原来的了,那么这个解释器在哪个文件夹目录下呢?经过我的百度在这里,(默认的)
C:\Users\zjw\AppData\Local\conda\conda\envs\first_name
使用jupter notebook
因为刚配置的python虚拟环境,什么包都没有 jupter 也是一样的,那就安装jupter就好了
1,安装 (有人说pip install jupyter 也好用,没试过,但是下面的好使 亲测)
pip install ipykernel
2,启动
jupyter notebook
查找当前解释器位置:使用代码查找进入Prompt给窗口激活我的环境输入代码查找
import sys
import os
print('当前 Python 解释器路径:')
print(sys.executable)
#C:\Users\zjw\AppData\Local\conda\conda\envs\first_name\python.exe
演示过程:
系统找不到指定的路径。
C:\Users\zjw>set "GDAL_DRIVER_PATH="
(base) C:\Users\zjw>conda create -n first_name python=3.6
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.4.10
latest version: 4.6.14
Please update conda by running
$ conda update -n base conda
## Package Plan ##
environment location: C:\Users\zjw\AppData\Local\conda\conda\envs\first_name
added / updated specs:
- python=3.6
The following packages will be downloaded:
package | build
---------------------------|-----------------
python-3.6.8 | h9f7ef89_7 20.3 MB
wheel-0.33.4 | py36_0 57 KB
certifi-2019.3.9 | py36_0 156 KB
setuptools-41.0.1 | py36_0 663 KB
vc-14.1 | h0510ff6_4 6 KB
vs2015_runtime-14.15.26706 | h3a45250_4 2.4 MB
sqlite-3.28.0 | he774522_0 945 KB
pip-19.1.1 | py36_0 1.9 MB
------------------------------------------------------------
Total: 26.4 MB
The following NEW packages will be INSTALLED:
certifi: 2019.3.9-py36_0
pip: 19.1.1-py36_0
python: 3.6.8-h9f7ef89_7
setuptools: 41.0.1-py36_0
sqlite: 3.28.0-he774522_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_4
wheel: 0.33.4-py36_0
wincertstore: 0.2-py36h7fe50ca_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
python 3.6.8: ##############2 | 15%
wheel 0.33.4: ################################################################################################# | 100%
certifi 2019.3.9: ############################################################################################# | 100%
setuptools 41.0.1: ############################################################################################ | 100%
vc 14.1: ###################################################################################################### | 100%
vs2015_runtime 14.15.26706: ################################################################################### | 100%
sqlite 3.28.0: ################################################################################################ | 100%
pip 19.1.1: ################################################################################################### | 100%
ChunkedEncodingError(ProtocolError('Connection broken: OSError("(10054, \'WSAECONNRESET\')",)', OSError("(10054, 'WSAECONNRESET')",)),)
(base) C:\Users\zjw>conda create -n first_name python=3.6
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.4.10
latest version: 4.6.14
Please update conda by running
$ conda update -n base conda
## Package Plan ##
environment location: C:\Users\zjw\AppData\Local\conda\conda\envs\first_name
added / updated specs:
- python=3.6
The following packages will be downloaded:
package | build
---------------------------|-----------------
python-3.6.8 | h9f7ef89_7 20.3 MB
The following NEW packages will be INSTALLED:
certifi: 2019.3.9-py36_0
pip: 19.1.1-py36_0
python: 3.6.8-h9f7ef89_7
setuptools: 41.0.1-py36_0
sqlite: 3.28.0-he774522_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_4
wheel: 0.33.4-py36_0
wincertstore: 0.2-py36h7fe50ca_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
python 3.6.8: ################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate first_name
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) C:\Users\zjw>conda activate first_name
(first_name) C:\Users\zjw>python
Python 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> quit()
(first_name) C:\Users\zjw>conda list
# packages in environment at C:\Users\zjw\AppData\Local\conda\conda\envs\first_name:
#
# Name Version Build Channel
certifi 2019.3.9 py36_0
pip 19.1.1 py36_0
python 3.6.8 h9f7ef89_7
setuptools 41.0.1 py36_0
sqlite 3.28.0 he774522_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.15.26706 h3a45250_4
wheel 0.33.4 py36_0
wincertstore 0.2 py36h7fe50ca_0
(first_name) C:\Users\zjw>
配置好环境后查看一下
1,打开anaconda下的navigator,发现了显示了我刚才创建的环境