官术网_书友最值得收藏!

  • Hands-On Neural Networks
  • Leonardo De Marchi Laura Mitchell
  • 252字
  • 2021-06-24 14:00:10

Understanding virtual environments 

While working with Python, you will probably use a multitude of libraries or packages. The virtual environment called venv is the first and most immediate way of making a working setup that is easy to reproduce.

From Python 3.3, the venv module is Python's built-in module, meaning you don't need to install any external components.

To create an environment in an automated way, it's necessary to create a list with all the libraries you want to install. Pip has a very simple way of defining this list, and it's enough to create a .txt file and specify one library per line.

To create the environment, you will need to perform the following steps:

  1. Install Python 3.7.
  2. Create a new environment called dl_venv_pip by using the following command:
python3.7 -m venv dl_venv_pip
  1. Specify the required libraries in a file that we will call requirements.txt, with the following content:
numpy==1.15.4
scipy==1.1.0
pandas==0.23.4
tensorboard==1.12.1
tensorflow==1.11.0
scipy==1.1.0
scikit-learn==0.20.1
Keras==2.2.4

  1. It's possible to now install all the required libraries with this command:
pip install -r /path/to/requirements/requirements.txt
  1. Now we can activate our environment by typing in the following command:
source dl_venv_pip/bin/activate

Once the environment is activated, all your calls to the Python interpreter will be redirected to the environment's interpreter. It's a quick and easy way to distribute the requirements, but it's still possible to have compatibility issues due to different operating systems, and also it might require some time to install all libraries as many data science projects rely on many of them.

主站蜘蛛池模板: 宣城市| 青冈县| 连江县| 中卫市| 玛曲县| 古蔺县| 慈溪市| 滨州市| 南京市| 柏乡县| 凌海市| 陇西县| 沂南县| 门头沟区| 柞水县| 武汉市| 象山县| 丁青县| 尤溪县| 玛纳斯县| 五华县| 雅安市| 通化县| 阿图什市| 嘉善县| 深圳市| 德昌县| 乐东| 九台市| 沂水县| 安义县| 丹棱县| 日土县| 洛川县| 绥德县| 高尔夫| 涪陵区| 金阳县| 中西区| 炉霍县| 长沙县|