0

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
  • 107,083
  • 22
  • 201
  • 376
Isdj
  • 1,732
  • 1
  • 17
  • 33
  • 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

2 Answers2

1

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
  • 36,354
  • 15
  • 89
  • 140
Simon Kirsten
  • 2,384
  • 15
  • 20
0

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,431
  • 6
  • 22