[Part-2]Python environment Windows - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: Tutorials (https://python-forum.io/forum-4.html) +---- Forum: Python Installation and Execution (https://python-forum.io/forum-41.html) +---- Thread: [Part-2]Python environment Windows (/thread-3403.html) |
[Part-2]Python environment Windows - snippsat - May-20-2017 Part-1 is here,which contend basic install Python and use of pip to install 3-party modules.A little more about pip, wheel, package creation, virtual environment and setting up stuff like a better cmd. Package creation will be in Part-3. A much better cmd cmder. Download to a folder eg C:\cmder One setup that important is .\cmder.exe /REGISTER ALL This make a shortcut link to cmder as in image under. So from any folder i file explorer direct to cmder in that folder. [Image: kGAwLo.jpg] PIP The tool for installing Python packages from PyPi or GitHub,BitBucket and more. pip is part of all Python version over 2.7.9(just remember to mark on under install).Useful commands:
Virtual environment The main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has. These dependencies can be written to a requirements.txt which we look at later.Virtual Environments is a part of Python 3.6 A folder with full Python install(including pip),that don't mess with OS Python. C:\ # Make virtual environment λ python -m venv my_env # cd into the folder C:\ λ cd my_env # Activate environment,in Linux is source bin/activate C:\my_env λ C:\my_env\Scripts\activate.bat # Now is folder active,you see (my_env) (my_env) C:\my_env # With cmder i can check that right python is used λ which python /c/my_env/Scripts/pythonRunning this code find_title.py in virtual environment.So need to install BeautifulSoup, Requests, lxml into virtual environment. # find_title.py import requests from bs4 import BeautifulSoup def find_title(url): url_get = requests.get(url) soup = BeautifulSoup(url_get.content, 'lxml') print(soup.select('head > title')[0].text) if __name__ == '__main__': #url = 'http://CNN.com' url = 'https://www.python.org/' find_title(url) (my_env) C:\my_env # Check that pip in environment is used λ pip -V pip 9.0.1 from c:\my_env\lib\site-packages (python 3.6) # install BeautifulSoup, Requests, lxml (my_env) C:\my_env λ pip install beautifulsoup4 requests lxml Collecting beautifulsoup4 Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB) 100% |████████████████████████████████| 92kB 803kB/s Collecting requests Downloading requests-2.14.2-py2.py3-none-any.whl (560kB) 100% |████████████████████████████████| 563kB 1.4MB/s Collecting lxml Using cached lxml-3.7.3-cp36-cp36m-win32.whl Installing collected packages: beautifulsoup4, requests, lxml Successfully installed beautifulsoup4-4.6.0 lxml-3.7.3 requests-2.14.2Running code: (my_env) C:\my_env λ python find_title.py Welcome to Python.orgMake requirements.txt for this virtual environment.(my_env) C:\my_env λ pip freeze > requirements.txt So we see which version that are used,if something break in future we can now see that with these versions it did work. Can also install with it. pip install -r requirements.txt Overview image: [Image: xE84P5.jpg] RE: [Part-2]Python environment Windows - metulburr - May-23-2017 I think there should be a distinct part that says you dont have to use environments. This is how to install to your OS python and this how to install via environment,etc. Some users could care less about them...especially when they are just trying to get their tutorials to run. Here it implies that you must use one. RE: [Part-2]Python environment Windows - sparkz_alot - May-23-2017 (May-23-2017, 10:33 AM)metulburr Wrote: Some users could care less about them Ok, I confess! I have never used a virtual environment, though it is nice to see an example of how to do it, should I ever find the need. RE: [Part-2]Python environment Windows - snippsat - May-23-2017 I have update with purpose of virtual environment for both Windows and Linux tutorial. An describe better that Part-1 has the basic stuff. RE: [Part-2]Python environment Windows - metulburr - May-24-2017 (May-23-2017, 02:17 PM)sparkz_alot Wrote: Ok, I confess! I have never used a virtual environment, though it is nice to see an example of how to do it, should I ever find the need.I have used them. But i fail to see the need. And i have never needed to use different library versions simultaneously on different programs. Usually the latest is fine. And i usually prefer tuts that dont use environments as i like to see it raw on the system. It adds an extra layer of complexity when your just trying to understand the tutorial alone. Especially if you have never used one before. Then you end up spending most of your time dicking with the environment and/or converting it to your OS Python than actually understanding the tutroial. I bet those that dont know about pip and how to install a python 3rd library via pip could care less about an environment. Though the transition is easy in our eyes to use it on your OS Python, those just starting out have no idea. im not knocking your method snippsat, im just trying to think of it in terms of a new user. I dont think most would follow suit and install cmder or use an environment. Quote:(my_env) C:\my_env this would look foreign to me. For one because most likely a new user would not use an environment. Most have never even used the terminal/command line before ever. And second no new user starts off with cmder. Though it is nice, new users would look at it like it looks nothing like mine. Out of all that all they really need to know is pip install beautifulsoup4 requests lxml |