Press "Enter" to skip to content

Python work environment

Let’s talk about what “Python Virtual Environment” is first. The Turkish equivalent is a virtual environment, or a virtual working environment. It is a system that is running exactly isolated from the system, allowing you to collect the python version you selected and the modules you want to use in one place. Creates a custom python field for you.

With the virtual environment, you can develop your projects regardless of the system. Although it is not very necessary for Windows users, I don’t think it’s necessary unless you work with the same modules and different versions. It is a necessary system for Mac and linux users. Because dependencies of programs that are in the operating system that are critical to the system may be linked to the module you want to use in your project. If you make changes to this module(version change or update), you may disrupt the system’s stable operation.

At the same time, all files and modules related to your project are simple and easy to manage because they are in one place. That’s why it’s important to carry out projects with a virtual work environment.

How to set up a working environment?

If your system has a PIP (python package manager),

pip install virtualenv

you can perform setup with the command. If your system doesn’t have a pip installed, you should set it up first. You can setup from this article I wrote earlier.

I keep assuming you’ve set up pips. After you set up the virtual work environment with the command I gave, you can type and look at the output of the following code to confirm that the setup process has occurred. If it gives you a version number, you have successfully completed the setup.  🙂

virtualenv --version

Create a virtual work environment

We’ve built everything, now it’s time to create a virtual environment and do the first attempt. To do this, you must first go to that location from the terminal or at the command prompt,[1], or /home/kenan/Python/. After you go to the location, you can create the virtual environment by entering the command below.

virtualenv {work media name}

Let me drop a small note, if your system has two different python versions, a virtual environment is created with the python version selected by default. I have both 2.7 and 3.5 versions, I want to create a virtual environment with 3.5, so I’m going to go to the “python3 -m venv” command.

I created and entered a folder named “env”, viewed the files in it with the LS command, and created a virtual work environment called blank, “python3 -m venv firstProject”, i checked the files in the folder again with the LS command, and the working environment I saw it was created. 

When we look into this virtual work environment that is created, it will look like this.

Folders with the files and modules required for python to work. Our project will be located in this folder. If you want, you can create a new folder and collect it in it. You can also work directly inside this folder if you want.

This is not only about creating a virtual environment, now it’s time to run it. After you create the virtual environment, you need to run with the “activate” file inside the bin folder. If you want to do this, you can go into that folder and run it (through the console, of course), or you can run the path to the full folder by typing it from the terminal.

source /home/kenan/env/ilkProject/bin/activate

If you have not done the wrong type at the address, this is exactly what the image you will encounter will be. If your project name is at the beginning of the name, you have successfully run the virtual environment.

Just add .bat to the end in Windows. I can’t show pictures because I’m not using Windows, I’m sorry. But if you do research on the Internet, it’s possible to find resources.

For example, let’s install a module in a virtual environment. Let’s load the django. With this screen on, let’s just write this code and print it out.

He’s found the Django module, he’s downloading it.

It has set up and is ready for use. Now we can use djangoyu in our project.

It’s as simple as creating a virtual environment and installing modules through pip.

You’ve created, activated, installed modules, and you’re done, let’s just say you have to give the following command to turn off the virtual environment.

Deactivate

We’ve turned off the virtual environment, that’s all.

This may sound complicated, but don’t make a big deal out of your eyes. After a few uses, you’ll see how simple it is. If you don’t use this system, you need to manually download the modules and throw them into the python yourself. With this process, everything is automated 🙂  

If you still say you can’t deal with this much confusion, I suggest you use pycharm, which is also a virtual environment for you. The next topic is on pycharm 🙂 plenty of coded days 🙂

Source:

https://docs.python.org/3/tutorial/venv.html

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *