0

I'm trying to make an application in Python that will be run from a USB drive on a variety of different computers. Let's just assume for a second that the client computer has Python installed and put that to one side.

My application uses cherrypy to launch a local web server, but it's safe to assume that this won't be already installed on the computer it's run on.

What would be the best of addressing this problem as transparently as possible?

It should be usable by a non-technical user and they shouldn't have to worry about installing any dependencies themselves.

At the moment, I've packaged a copy of the cherrypy source with my app and if the program detects that it isn't already installed, it runs the setup.py but with the --user flag, avoiding any permissions issues.

This doesn't seem like great practice.

Is it possible to just include the built package with my app? I've tried doing this with something like the following:

/myapp/libs/cherrypy

I copied the cherrypy directory from the CherryPy archive. This is pre-build, and so probably won't work. I also tried an alternative where I run setup.py (which created a build directory) and copied those files instead.

/myapp/somefile.py

import myapp.libs.cherrypy as cherrypy

In theory, this should work... But it doesn't. When I try to run the server (using cherrpy.quickstart()) it runs two instances of the server, which obviously starts causing problems.

So, the question(s): First off, am I going about this completely the wrong way? How can I make a third-party package available to my app?

1 Answer 1

1

This is due to PYTHONPATH issues. I would recommend using virtual envs and pip as standard when working with packages you've imported or obatined externally.

Some great notes here: https://python-guide.readthedocs.org/en/latest/

If you wnat to import your own code. I'd set your PYTHONPATH (in the case below the dev_folder) to a root development directory and follow this structure...

dev_folder \
- project_name \
    - main_script.py
    - helper.py
    - libary1 \
        - __init__.py
        - lib1.py
    - libary2 \
        - __init__.py
        - lib2.py

You'd obviously come up with better names for the library folders/packages :-)

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply, I've read a little bit about virtualenv and just had another quick quuestion. Do I run virtualenv at the start of development and then sort of 'leave it be'. I.e. That virtual environment will work cross-platform, or is each virtual environment generated specific to the platform it's run on? If the latter, would the computer running my app have to run virtualenv each time the app is run?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.