- Python Penetration Testing Cookbook
- Rejah Rehim
- 305字
- 2021-07-02 23:08:39
Setting up a virtual environment
Now you can learn to set up a virtual environment that will help to set up an isolated scripting environment. This will help us to keep the dependencies required by different projects in different locations. Also, it helps to keep the global site-packages clean and separate from project dependencies:
- You can use pip to install the virtual environment module in the system:
$ pip install virtualenv
- Then test the installation by using the following:
$ virtualenv --version
- Try creating a new virtual environment inside your project folder:
$ mkdir new-project-folder $ cd new-project-folder $ virtualenv new-project
This will create a folder in the current directory with a name new-project.
If you want to create a virtual environment with a Python interpreter of your choice as follows:
$ virtualenv -p /usr/bin/python3 new-project
- You can activate this virtual environment with the following:
$ source new-project/bin/activate
- If you have completed your work inside the virtual environment, you can deactivate and get out of the virtual environment with the following:
$ deactivate
- We can make it simpler with virtualenvwrapper. The virtualenvwrapper helps to keep all our virtual environments in one place. To install virtualenvwrapper we can use the pip command:
$ pip install virtualenvwrapper
We have to set the WORKON_HOME variable, which is the folder where all the virtual environments are saved:
$ export WORKON_HOME=~/Envs $ source /usr/local/bin/virtualenvwrapper.sh
- With virtualenvwrapper we can create a project as follows:
$ mkvirtualenv new-project
This will create the virtual environment inside the WORKON_HOME, that is, ~/Envs.
- To activate the created project we can use the following command:
$ workon new-project
- With more ease we can create a virtual environment and the project folder with a single command as follows:
$ mkproject new-project
- Finally, we can exit from the virtual environment with the deactivate command itself.
推薦閱讀
- Securing Blockchain Networks like Ethereum and Hyperledger Fabric
- CSO進階之路:從安全工程師到首席安全官
- 深入淺出隱私計算:技術解析與應用實踐
- 安全實戰之滲透測試
- INSTANT Windows PowerShell
- 解密彩虹團隊非凡實戰能力:企業安全體系建設(共5冊)
- 數據要素安全:新技術、新安全激活新質生產力
- CTF特訓營:技術詳解、解題方法與競賽技巧
- 網絡空間安全:拒絕服務攻擊檢測與防御
- Mastering Linux Security and Hardening
- 網絡空間安全法律問題研究
- 一本書讀透金融科技安全
- Blockchain Development with Hyperledger
- 2010年中國互聯網網絡安全報告
- Developing Applications with Salesforce Chatter