PYTHONPATH: dev and prod

rusi rustompmody at gmail.com
Wed Jun 12 12:10:05 EDT 2013


On Jun 12, 6:29 pm, jacopo <jacopo.pe... at gmail.com> wrote:
> > 1. How you run -- 'launch' -- the code -- from py and from prod
>
> when I have to test I use "python any_script.py"  but in production there is a c++ program that is able to wrap and run python code (the technical details are a bit beyond my knowledge)
>
> > 2. What error you get
>
> when I run as "python any_script.py" I get
> "ValueError: Attempted relative import in non-package"
> I have found this explanation:http://stackoverflow.com/questions/11536764/attempted-relative-import...
> So I have added at the top of my module:
>
> if __name__=="__main__" and __package__ is None:
>      __package__="myscripts"
> from ..mylib import MyClass
>
> and I get the error:
> SystemError: Parent module 'mylib' not loaded, canno perform relative import
>
> > 3. Did you try bundling your modules into a package? What problem
> > happened?
>
> What does it mean? what does build mean in this contest? I am not compiling, I just write the .py files.

I mean use a python package to wrap the modules.
Roughly that means have a file named __init__.py in the root of your
modules directory.
For the details see http://docs.python.org/2/tutorial/modules.html#packages

More intricacies I dont know. Hopefully someone who knows better can
answer



More information about the Python-list mailing list