lopuniversal.blogg.se

How to create a application with a .py file
How to create a application with a .py file













  1. #How to create a application with a .py file install
  2. #How to create a application with a .py file update
  3. #How to create a application with a .py file code

#How to create a application with a .py file update

We need to update the setup.py file to accommodate that the program is more complex than what it was before. Print('This is function_a') def function_b(): Let's develop two very simple function inside file_a and file_b, respectively: def function_a(): Let's create now a package with tho modules, the folder structure will look like this. As soon as your program starts having multiple files, you will need to structure it in such a way that setup knows what files are needed. In the example above we had only one script available, and thus the structure of the program was straightforward. This is great, now you have a way of using your program from anywhere else, even from other packages. For example, change your directory to anywhere else on your computer, and to the following: from first import first_function More importantly, you can now use your package from anywhere else on your computer. You will see some information printed to the screen.

#How to create a application with a .py file install

To install your script, you can simply do the following from the console: python setup.py install

#How to create a application with a .py file code

The code we are developing is harmless, nevertheless, it is always wise to create a virtual environment to play around, and eventually discard once you understood and polished the details Next to the file, let's create a new file called setup.py, with the following code: from setuptools import setup What we would like to be able to achieve is to run code like this: from first import first_function This file is what we want to be able to use from other packages, etc. Let's start by creating a file called first.py, with the following code inside: def first_function(): You should start on an empty directory, the name doesn't matter, but it is important not to mix it with other things, so you can follow this article without complications. The examples we are going to develop are toy examples, very similar to the ones on the article about importing. Having a setup.py file is the first step into being able to switch from scripts to a package on which to rely. It will also be possible to quickly distribute the code with other people, diminishing the barrier of adoption. With a proper setup file, Python will quickly understand where to find the package, and thus importing from other places becomes trivial. We have already seen that for importing to work properly, it is very important to have well-defined packages, and that Python knows where to find them.

how to create a application with a .py file

Sometimes it is handy if you can quickly use the code you developed yourself in the past on a new machine or a different virtual environment. When you develop software, at some point you will want other people to be able to use what you have built. 20, 2020 environment path setup install package Why having a setup















How to create a application with a .py file