python3.6虛擬環境以及flask的安裝(常見問題)
阿新 • • 發佈:2017-08-11
python 虛擬環境 flask
準備基於python進行web應用開發
Python3.3以上的版本通過venv模塊原生支持虛擬環境,可以代替Python之前的virtualenv。
該venv模塊提供了創建輕量級“虛擬環境”,提供與系統Python的隔離支持。每一個虛擬環境都有其自己的Python二進制(允許有不同的Python版本創作環境),並且可以擁有自己獨立的一套Python包。
需要註意的是,在Python3.3中使用"venv"命令創建的環境不包含"pip",你需要進行手動安裝。在Python3.4中改進了這一個缺陷。
在當前目錄創建虛擬環境:
$ python -m venv .
下面是"venv"的詳細使用參數:
usage: venv [-h] [--system-site-packages] [--symlinks] [--clear] [--upgrade] [--without-pip] ENV_DIR [ENV_DIR ...] Creates virtual Python environments in one or more target directories. positional arguments: ENV_DIR A directory to create the environment in. optional arguments: -h, --help show this help message and exit --system-site-packages Give access to the global site-packages dir to the virtual environment. --symlinks Try to use symlinks rather than copies, when symlinks are not the default for the platform. --copies Try to use copies rather than symlinks, even when symlinks are the default for the platform. --clear Delete the environment directory if it already exists. If not specified and the directory exists, an error is raised. --upgrade Upgrade the environment directory to use this version of Python, assuming Python has been upgraded in-place. --without-pip Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
激活虛擬環境
在Posix標準平臺下:
$ source <venv>/bin/activate
在Windows cmd下:
C:> <venv>/Scripts/activate.bat
在Windows PowerShell下:
PS C:> <venv>/Scripts/Activate.ps1
測試虛擬環境
激活虛擬環境後,在命令行會提示當前虛擬環境的名稱,就表示激活成功了。
不過從今天下午就開始安裝環境,中間碰見了兩次問題,花費了大巴時間,因而把問題和解決方法寫出來供大家參考使用
第一個問題
創建虛擬環境中 scripts中怎麽沒有activate
解決方法 把版本換成3.60 我的 3.62嘗試了三次都沒成功
最後把python版本換成3.60了一下子成功了
虛擬環境安裝成功後 進入虛擬環境 安裝flask
pip install flask
這個錯誤問題忘記截圖了
主要就是紅色的編碼錯誤
這樣的錯誤可以忽略
推出虛擬環境 再從新安裝就好了
本文出自 “大李子” 博客,謝絕轉載!
python3.6虛擬環境以及flask的安裝(常見問題)