2

I have written a python27 module and installed it using python setup.py install.

Part of that module has a script which I put in my bin folder within the module before I installed it. I think the module has installed properly and works (has been added to site-packages and scripts). I have built a simple script "test.py" that just runs functions and the script from the module. The functions work fine (the expected output prints to the console) but the script does not.

I tried from [module_name] import [script_name] in test.py which did not work.

How do I run a script within the bin of a module from the command line?

2 Answers 2

1

Are you using distutils or setuptools?

I tested right now, and if it's distutils, it's enough to have

scripts=['bin/script_name']

in your setup() call

If instead you're using setuptools you can avoid to have a script inside bin/ altogether and define your entry point by adding

entry_points={'console_scripts': ['script_name = module_name:main']}

inside your setup() call (assuming you have a main function inside module_name)

are you sure that the bin/script_name is marked as executable?

what is the exact error you get when trying to run the script? what are the contents of your setup.py?

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

Comments

0

Please check your installed module for using condition to checking state of global variable __name__. I mean:

if __name__ == "__main__":

Global variable __name__ changing to "__main__" string in case, then you starting script manually from command line (e.g. python sample.py). If you using this condition, and put all your code under this, it will be be work when you will try to import your installed module from another script. For example (code from module will not run, when you will import it):

testImport.py:

import sample
...another code here...

sample.py:

if __name__ == "__main__":
    print "You will never see this message, except of case, when you start this module manually from command line"

Comments

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.