Mailing List Archive

Importing from within package
Greeting list,

I have this main script:
https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py

However, i get errors after package installation
saying:
ImportError: cannot import name 'shopyoapi' from 'shopyo'

I've tried from .shopyoapi also but to no avail.

To reproduce:

python -m pip install shopyo==1.1.45
shopyo new . test2

Thanks!

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://abdur-rahmaanj.github.io/>
github <https://github.com/Abdur-RahmaanJ>
Mauritius
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
>
> On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer
> <arj.python@gmail.com> declaimed the following:
>
> >I have this main script:
> >https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py
> >
>
> Well, that file name scares me...
>
> __main__ is the name Python uses internally for the, well, main program
> (whatever the real file name is), and becomes part of the convention
>
> if __name__ == "__main__":
> #running as stand-alone program
> #do stuff
>
> where imported files will appear with the name by which they were imported.
>

In a package, __main__.py does that same job.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
On 9/22/2020 8:31 PM, Chris Angelico wrote:
> On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
>>
>> On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer
>> <arj.python@gmail.com> declaimed the following:
>>
>>> I have this main script:
>>> https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py
>>>
>>
>> Well, that file name scares me...
>>
>> __main__ is the name Python uses internally for the, well, main program
>> (whatever the real file name is), and becomes part of the convention
>>
>> if __name__ == "__main__":
>> #running as stand-alone program
>> #do stuff
>>
>> where imported files will appear with the name by which they were imported.
>>
>
> In a package, __main__.py does that same job.

I am not sure of your intended meaning.

Assume that director 'mypac' is in a directory on sys.path. Forget
namespace packages, which I have not studied.
'import mypac' within code imports mypac/__init__.py
'python -m mypac' on a command line runs mypac/__main__.py

Example: .../pythonxy/lib/idlelib. lib is on sys.path.
idlelib/__init__.py is nearly empty.
idlelib/__main__.py starts IDLE,
so 'python -m idlelib' on a command line starts idle.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
Chris Angelico <rosuav@gmail.com> writes:

> ...
> In a package, __main__.py does that same job.

Sorry ChrisA, would you please some example? Because i am working in
progress with Python things...

Sicnerely, Byung-Hee

--
^????? _????_ ?????_^))//
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
On Wed, Sep 23, 2020 at 2:16 PM Terry Reedy <tjreedy@udel.edu> wrote:
>
> On 9/22/2020 8:31 PM, Chris Angelico wrote:
> > On Wed, Sep 23, 2020 at 9:24 AM Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> >>
> >> On Tue, 22 Sep 2020 20:14:01 +0400, Abdur-Rahmaan Janhangeer
> >> <arj.python@gmail.com> declaimed the following:
> >>
> >>> I have this main script:
> >>> https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py
> >>>
> >>
> >> Well, that file name scares me...
> >>
> >> __main__ is the name Python uses internally for the, well, main program
> >> (whatever the real file name is), and becomes part of the convention
> >>
> >> if __name__ == "__main__":
> >> #running as stand-alone program
> >> #do stuff
> >>
> >> where imported files will appear with the name by which they were imported.
> >>
> >
> > In a package, __main__.py does that same job.
>
> I am not sure of your intended meaning.
>
> Assume that director 'mypac' is in a directory on sys.path. Forget
> namespace packages, which I have not studied.
> 'import mypac' within code imports mypac/__init__.py
> 'python -m mypac' on a command line runs mypac/__main__.py
>
> Example: .../pythonxy/lib/idlelib. lib is on sys.path.
> idlelib/__init__.py is nearly empty.
> idlelib/__main__.py starts IDLE,
> so 'python -m idlelib' on a command line starts idle.
>

Correct. I was a bit too brief there, but Terry's elaboration is what
I was getting at: that __main__.py is a valid and normal member of a
package, and will be used as the entry point.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
Greetings list,

In case this might help, i am on Python3.8 and running in a virtual env
This command also does not work:
python -m shopyo new . test2

Kind Regards,

Abdur-Rahmaan Janhangeer
about <https://compileralchemy.github.io/> | blog
<https://abdur-rahmaanj.github.io/>
github <https://github.com/Abdur-RahmaanJ>
Mauritius
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
Abdur-Rahmaan Janhangeer wrote at 2020-9-22 20:14 +0400:
>I have this main script:
>https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/__main__.py
>
>However, i get errors after package installation
>saying:
>ImportError: cannot import name 'shopyoapi' from 'shopyo'

It is right: `shopyyoapi` is not a module (no corresponding file in
`shopyo` and `shopyo:__init__.py` does not define a corresponding name.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
In shopyo/shopyo (the same folder as __main__.py) there is a folder called
shopyoapi.

What i want is to import create_module from cmd.py from shopyoapi in
__main__.py but it does not work or more precisely i am looking how to make
it work!

Since this is not py2 i guess no init needed in shopyoapi

Kind Regards,


Abdur-Rahmaan Janhangeer

https://www.github.com/Abdur-RahmaanJ

Mauritius

sent from gmail client on Android, that's why the signature is so ugly.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
Abdur-Rahmaan Janhangeer wrote at 2020-9-23 22:41 +0400:
>In shopyo/shopyo (the same folder as __main__.py) there is a folder called
>shopyoapi.

Not in the distribution:
...
shopyo-1.1.45/shopyo/
shopyo-1.1.45/shopyo/__init__.py
shopyo-1.1.45/shopyo/__main__.py
shopyo-1.1.45/shopyo/app.py
shopyo-1.1.45/shopyo/config.py
shopyo-1.1.45/shopyo/manage.py
shopyo-1.1.45/shopyo/test_frontend.py
shopyo-1.1.45/shopyo.egg-info/
...

Maybe, that is your problem (missing folder in the distribution).
--
https://mail.python.org/mailman/listinfo/python-list
Re: Importing from within package [ In reply to ]
Thanks for the lead. Checking tomorrow!
If so i'll have to include other folders as well ...

Kind Regards,


Abdur-Rahmaan Janhangeer

https://www.github.com/Abdur-RahmaanJ

Mauritius

sent from gmail client on Android, that's why the signature is so ugly.
--
https://mail.python.org/mailman/listinfo/python-list