1

I have a Python project created in PyCharm. Now that it's finished I want to make it available without PyCharm (making it an executable is not relevant). It consists of different packages and quite a few files inside each package. How can I export the project so I can run it from one file that will call the rest?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Isdj
  • 1,835
  • 1
  • 18
  • 36
  • 1
    Export it *where?* Do you want other people to be able to download and use it (e.g. from PyPI)? Who is your target audience (end users, developers, ...)? – jonrsharpe Jun 14 '16 at 12:07
  • I am interested to have it as a single file i can keep on my disc on key and run it wherever I go – Isdj Jun 14 '16 at 12:08
  • That doesn't really explain *why*. If it's just for your own use, why don't you just copy the package across and be done with it? What are you actually trying to *achieve?* Is it making the Python execution environment (interpreter and any required non-standard library packages) available that's the problem you're really trying to solve? – jonrsharpe Jun 14 '16 at 12:09
  • Because it cant be simply run by python and needs to be opened and run in PyCharm – Isdj Jun 14 '16 at 12:10
  • That seems pretty unlikely, frankly - why do you think that? What are the errors you get when you try to run it elsewhere? Please **give us more information**, as it stands it's really hard to figure out what problem you need help solving. See e.g. [ask]. – jonrsharpe Jun 14 '16 at 12:11
  • It seems like ill have to compile and make every package in to a module of its own and then install it on python. I would like to know if there is a way to pack it all in to one file instead of having to install modules every time I want to use it on a different pc – Isdj Jun 14 '16 at 12:15
  • I don't know how or why you've come to that conclusion. Python is an interpreted language, so unless you're using e.g. C extensions you shouldn't have to *"compile and make"* anything at all. Please [edit] the question to explain **what you're actually trying to do**, along with what you've tried ([mcve]) and where precisely you got stuck, otherwise we're just making guesses. – jonrsharpe Jun 14 '16 at 12:18
  • Pull up a shell or console, change to the project directory and run `python whateveryourmainfileis.py`. If that works, just zip your whole project directory and put it on another machine. – Alastair McCormack Jun 14 '16 at 15:20
  • It's alarming how noob un-friendly the comments here are. I'm in the same boat, I'm new to python and have no idea how to export my python project as a standalone executable that can be used with command line or called by other software. For example in xcode you just go product>archive>distribute content>built products and you get a standalone executable clt with all of it's dependencies included. I tried making my project.py executable with chmod, but when I attempt to execute it from command line it fails due to it's first external dependancie. How do you export your python clt? – Johnson Dec 07 '22 at 14:48
  • You're probably looking for this: https://www.youtube.com/watch?v=IIAlkQEw8Gc – Johnson Dec 08 '22 at 17:13

3 Answers3

1

So the answer to your question is that it's complicated, but what you want to do is package your app and make it distributable. This means including the python interpreter in the app as well as all of its dependancies so that anyone can use it without first installing python or anything additional to your app.

BeeWare's Briefcase does the heavy lifting in packaging in this way:

Visit their github and follow the tutorial: https://github.com/beeware/briefcase

Johnson
  • 161
  • 9
0

If you do not want to publish the project and just use it for yourself:

  1. Create a new __main__.py in your project root directory and start your program from there (by importing the old main.py etc.)

  2. Make sure the program runs as expected: Run python __main__.py [arguments] in the root directory.

  3. If this works, zip the whole project directory using an archiver and use like this:

    python myproject.zip [arguments]

Robert
  • 39,162
  • 17
  • 99
  • 152
Simon Kirsten
  • 2,542
  • 18
  • 21
-1

Think of PyCharm as a notepad/gedit - text editor of sorts. You can simply save the file with any name and a .py extension.

Now, to make it interpretable by Python interpretor, do the following:

import math  # an example import
# other imports


class SomeClass:
    def __init__(self):
        self.x = None

def someFnc():
    pass

def starting_point():
    # Make sure your logic begins execution here
    # e.g. use someFnc() or SomeClass here

if __name__ == '__main__':
    starting_point()

Above template will make your .py file ready for interpretation. That is to say, on a shell/cmd you can write this:

$> python your_file.py
anurag
  • 1,715
  • 1
  • 8
  • 28