Data Science Certification Training with Pyth ...
- 87k Enrolled Learners
- Live Class
Python, as we know, has achieved tremendous acclaim over the past few years for its simplicity and portability of code between platforms. However, where do we start off writing the python code? The main reason for the environment is to create an isolated area for the development of individual projects. This allows each project to have its no dependencies regardless of other projects stored on the computer with its specific requirements. In this article, we will understand the Python Environment.
To convert any code you need an Interpreter, which involves 70% of the application. Then you would need a “bang line”. There are primarily two ways to create this. Either you could choose to create a program using a simple text editor like WordPad or Notepad ++ or simply create a python shell on a putty platform. Each of them has its pros and cons. A shell can be used to interact with the OS, for instance, a “terminal” can be used to harness the windows OS. In a shell, the interpretation of your code happens in real-time, which is very beneficial. It gives you an idea of the possible errors and the code execution output.
Below is a piece of code which is run in a Python IDE (Integrated Development Environment) like PyCharm to give the desired output.
while(1) #!/usr/bin/env python #get the username from a prompt username=raw_input(“Login : “) #list of allowed users Participant1=”Pranav” Participant2=”Radhika” #control the input user If (username= =Participant1): print “access given” elif (username == Participant2): print “hello” else: print “access not granted” #end
For the Windows OS, the best place to get the python setup is from the official site of course which is www.python.org. MAC OS X computers already have python installed. Linux also follows suite with most computers having it pre-installed.
It is widely recommended to be using python 3 installed with Homebrew. Then go ahead and install “virtualenv” using pip3. As all the packages get copied we need to establish the location of our environment which can be done by:
virtualenv -p python3 ~/virtEnv1
The term virtEnv1 is the name of the virtual environment and defines the exact path of our environment. After the environment is initiated, a file called “active” inside the bin folder. We set as the source as mentioned below.
In case you choose to deactivate the virtual environment, then type
Different Aspects of Python Environment
In a similar fashion, we can create many such environments and replicate the above process for different versions of python.
Python Environment Wrapper (PEW). PEW acts as a wrapper and it can be used just once. It makes working on the virtual environment very easy. Using a single command, you can create a new environment instantly after installing a few packages.
VENV is another such virtual environment tool that is most recommended. It generates a configuration file, which is directly understood by python and refrains from copying the binary to newer locations. However, the only catch is it does not support versions 3.3 and below.
PIPENV takes things to all new arena as it combines packages and environments supported into a single tool. Just the specification of the environment is needed and it creates separate sections for different purposes like production, testing, and development.
The python setup comes with a number of modules and packages which follows a defined set of process for downloading, storing and unpacking these files. Whenever we store a project or try to retrieve a package, python accesses a unique child path of the main folder in which it was installed initially. There are some libraries referred to as site-packages or third-party packages, these are nothing but the user-created files. The other type is called system packages that are the python defined standard libraries.
This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. The Python installer sometimes presets PYTHONPATH.
It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as “.pythonrc.py” in Unix and it contains commands that load utilities or modify PYTHONPATH.
It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.
It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.
If this is set, it names a callable using dotted-path notation. The module will be imported and then run by the default implementation of sys.breakpointhook() which itself is called by built-in breakpoint(). If not set, or set to the empty string, it is equivalent to the value “pdb.set_trace”. Setting this to the string “0” causes the default implementation of sys.breakpointhook() to do nothing but return immediately.
With this, we come to an end of this Python Environment article. To get in-depth knowledge on Python along with its various applications, you can enroll here for live online training with 24/7 support and lifetime access.
Got a question for us? Mention them in the comments section of this Python Environment article and we will get back to you.