From stevegambino at gmail.com Wed Nov 1 15:29:23 2017 From: stevegambino at gmail.com (Steve Gambino) Date: Wed, 01 Nov 2017 19:29:23 +0000 Subject: [TriPython] Problems with import after attempting to create pip installable package Message-ID: Hello friends, I'm attempting to learn how to create a pip installable package. So far the attempt has been relatively successful but for one nagging issue. I'm hoping if I describe the issue here clearly enough that someone can offer pointers to help me get to a resolution. I've created the package (named get_random) successfully with setuptools and have been able to do a pip install of it in a virtualenv. The package "get_random" contains a trivial program also named "get_random". The program, "get_random", imports one module, 'random', and it has the functions, main(), get_random() and print_random(). After the pip install of the get_random package, I can call the get_random program from the command line in the virtualenv and get the expected results. In otherwords, if I run the following in a terminal I get a resulting random number, like so: sgambino-m1:~/vnv_for_pip > get_random 0.0259274305036 However, if I try to import the get_random package into a python REPL I do not see a complete list of what is in the package. I only see the following: >>> dir(get_random) >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] but I was expecting to see: >>> dir(get_random) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'get_random', 'main', 'print_random', 'random'] If I try to import the get_random package into a script and run the script, I get the following error: ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py Traceback (most recent call last): File "./try_get_random.py", line 5, in get_random.print_random() AttributeError: 'module' object has no attribute 'print_random' Here is some more detail from the REPL that may give a clue. I'm wondering if there is something in the setup.py that I haven't defined correctly or not defined at all. I could share that if someone thinks it is worth a look. The setup.py that I started with was the one that is provided from https://github.com/pypa/sampleproject Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import get_random >>> dir(get_random) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] >>> print(get_random.__file__) /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc >>> print(get_random.__package__) None >>> print(get_random.__path__) ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] If you have bothered to read this far, I hope this has made some sense and I thank you for any ideas you may be willing to share! Steve Gambino -- Best, Steve -------------- next part -------------- Hello friends, I'm attempting to learn how to create a pip installable package. So far the attempt has been relatively successful but for one nagging issue. I'm hoping if I describe the issue here clearly enough that someone can offer pointers to help me get to a resolution. I've created the package (named get_random) successfully with setuptools and have been able to do a pip install of it in a virtualenv. The package "get_random" contains a trivial program also named "get_random". The program, "get_random", imports one module, 'random', and it has the functions, main(), get_random() and print_random(). After the pip install of the get_random package, I can call the get_random program from the command line in the virtualenv and get the expected results. In otherwords, if I run the following in a terminal I get a resulting random number, like so: sgambino-m1:~/vnv_for_pip > get_random 0.0259274305036 However, if I try to import the get_random package into a python REPL I do not see a complete list of what is in the package. I only see the following: >>> dir(get_random) >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] but I was expecting to see: >>> dir(get_random) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'get_random', 'main', 'print_random', 'random'] If I try to import the get_random package into a script and run the script, I get the following error: ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py Traceback (most recent call last): ** File "./try_get_random.py", line 5, in ****** get_random.print_random() AttributeError: 'module' object has no attribute 'print_random' Here is some more detail from the REPL that may give a clue.** I'm wondering if there is something in the setup.py that I haven't defined correctly or not defined at all. I could share that if someone thinks it is worth a look. The setup.py that I started with was the one that is provided from [1]https://github.com/pypa/sampleproject Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import get_random >>> dir(get_random) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__'] >>> print(get_random.__file__) /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc >>> print(get_random.__package__) None >>> print(get_random.__path__) ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] If you have bothered to read this far, I hope this has made some sense and I thank you for any ideas you may be willing to share! Steve Gambino -- Best,** Steve References Visible links 1. https://github.com/pypa/sampleproject From tobias at caktusgroup.com Wed Nov 1 18:27:59 2017 From: tobias at caktusgroup.com (Tobias McNulty) Date: Wed, 1 Nov 2017 18:27:59 -0400 Subject: [TriPython] seeking senior Python/data consultant with short-term travel flexibility Message-ID: Hi all, I'm looking for a senior technical consultant with Python & data management experience. Must have flexibility to travel internationally in the short term (2-4 weeks) and be comfortable with a dynamic work environment. If you're interested or can make a recommendation, please email me a CV off-list (individuals only, please). Thanks! *Tobias McNulty*Chief Executive Officer tobias at caktusgroup.com www.caktusgroup.com -------------- next part -------------- Hi all, I'm looking for a senior technical consultant with Python & data management experience. Must have flexibility to travel internationally in the short term (2-4 weeks) and be comfortable with a dynamic work environment. If you're interested or can make a recommendation, please email me a CV off-list (individuals only, please). Thanks! Tobias McNulty Chief Executive Officer [1]tobias at caktusgroup.com [2]www.caktusgroup.com References Visible links 1. mailto:tobias at caktusgroup.com 2. http://www.caktusgroup.com/ From david at handysoftware.com Wed Nov 1 22:07:39 2017 From: david at handysoftware.com (David Handy) Date: Wed, 1 Nov 2017 22:07:39 -0400 (EDT) Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: References: Message-ID: <1509588459.712518936@apps.rackspace.com> Hi Steve - I was a little confused reading your description, mainly because I wasn't sure when you said "package" whether you meant a distributable unit of Python code with a setup.py file, or whether you meant "an importable directory on sys.path containing an __init__.py file". Is there an importable package directory named "get_random" containing an __init__.py file? Or is there instead a get_random.py module? If you have an importable package directory named get_random, then the behavior you saw is expected. When you import a package, the only names you see in that package are the ones defined (or imported into) the __init__.py file itself. To see anything in any other module inside that package you have to import that explicity, in your main program file or in the __init__.py file. Which form does your get_random program take? There are at least two ways to distribute Python scripts, one that uses setuptools and console entry points, and one doesn't. Yes, if you shared your full setup.py file with us, that would probably answer those questions and more, and would be helpful in diagnosing your problem. If you would share the full layout of your distributable package files, that would help too. Thanks, David H On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" said: > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > Hello friends, > > I'm attempting to learn how to create a pip installable package. So far the > attempt has been relatively successful but for one nagging issue. I'm > hoping if I describe the issue here clearly enough that someone can offer > pointers to help me get to a resolution. > > I've created the package (named get_random) successfully with setuptools > and have been able to do a pip install of it in a virtualenv. > > The package "get_random" contains a trivial program also named > "get_random". The program, "get_random", imports one module, 'random', and > it has the functions, main(), get_random() and print_random(). After the > pip install of the get_random package, I can call the get_random program > from the command line in the virtualenv and get the expected results. In > otherwords, if I run the following in a terminal I get a resulting random > number, like so: > > sgambino-m1:~/vnv_for_pip > get_random > 0.0259274305036 > > However, if I try to import the get_random package into a python REPL I do > not see > a complete list of what is in the package. I only see the following: > > >>> dir(get_random) > >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > > but I was expecting to see: > > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'get_random', 'main', 'print_random', 'random'] > > If I try to import the get_random package into a script and run the script, > I get the following error: > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > Traceback (most recent call last): > File "./try_get_random.py", line 5, in > get_random.print_random() > AttributeError: 'module' object has no attribute 'print_random' > > Here is some more detail from the REPL that may give a clue. I'm wondering > if there is something in the setup.py that I haven't > defined correctly or not defined at all. I could share that if someone > thinks it is worth a look. The setup.py that I started with > was the one that is provided from https://github.com/pypa/sampleproject > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import get_random > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > >>> print(get_random.__file__) > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > >>> print(get_random.__package__) > None > >>> print(get_random.__path__) > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > If you have bothered to read this far, I hope this has made some sense and > I thank you for any ideas you may be willing to share! > Steve Gambino > -- > Best, > Steve > Hello friends, > I'm attempting to learn how to create a pip installable package. So far > the attempt has been relatively successful but for one nagging issue. I'm > hoping if I describe the issue here clearly enough that someone can offer > pointers to help me get to a resolution. > I've created the package (named get_random) successfully with setuptools > and have been able to do a pip install of it in a virtualenv. > The package "get_random" contains a trivial program also named > "get_random". The program, "get_random", imports one module, 'random', and > it has the functions, main(), get_random() and print_random(). After the > pip install of the get_random package, I can call the get_random program > from the command line in the virtualenv and get the expected results. In > otherwords, if I run the following in a terminal I get a resulting random > number, like so: > sgambino-m1:~/vnv_for_pip > get_random > 0.0259274305036 > However, if I try to import the get_random package into a python REPL I do > not see > a complete list of what is in the package. I only see the following: > >>> dir(get_random) > >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > '__path__'] > > but I was expecting to see: > > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'get_random', 'main', 'print_random', 'random'] > > If I try to import the get_random package into a script and run the > script, I get the following error: > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > Traceback (most recent call last): > ** File "./try_get_random.py", line 5, in > ****** get_random.print_random() > AttributeError: 'module' object has no attribute 'print_random' > > Here is some more detail from the REPL that may give a clue.** I'm > wondering if there is something in the setup.py that I haven't > defined correctly or not defined at all. I could share that if someone > thinks it is worth a look. The setup.py that I started with > was the one that is provided from [1]https://github.com/pypa/sampleproject > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import get_random > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > >>> print(get_random.__file__) > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > >>> print(get_random.__package__) > None > >>> print(get_random.__path__) > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > If you have bothered to read this far, I hope this has made some sense and > I thank you for any ideas you may be willing to share! > Steve Gambino > -- > Best,** > Steve > > References > > Visible links > 1. https://github.com/pypa/sampleproject > -------------- next part -------------- Hi Steve - I was a little confused reading your description, mainly because I wasn't sure when you said "package" whether you meant a distributable unit of Python code with a setup.py file, or whether you meant "an importable directory on sys.path containing an __init__.py file". Is there an importable package directory named "get_random" containing an __init__.py file? Or is there instead a get_random.py module? If you have an importable package directory named get_random, then the behavior you saw is expected. When you import a package, the only names you see in that package are the ones defined (or imported into) the __init__.py file itself. To see anything in any other module inside that package you have to import that explicity, in your main program file or in the __init__.py file. Which form does your get_random program take? There are at least two ways to distribute Python scripts, one that uses setuptools and console entry points, and one doesn't. Yes, if you shared your full setup.py file with us, that would probably answer those questions and more, and would be helpful in diagnosing your problem. If you would share the full layout of your distributable package files, that would help too. Thanks, David H On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" said: > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > Hello friends, > > I'm attempting to learn how to create a pip installable package. So far the > attempt has been relatively successful but for one nagging issue. I'm > hoping if I describe the issue here clearly enough that someone can offer > pointers to help me get to a resolution. > > I've created the package (named get_random) successfully with setuptools > and have been able to do a pip install of it in a virtualenv. > > The package "get_random" contains a trivial program also named > "get_random". The program, "get_random", imports one module, 'random', and > it has the functions, main(), get_random() and print_random(). After the > pip install of the get_random package, I can call the get_random program > from the command line in the virtualenv and get the expected results. In > otherwords, if I run the following in a terminal I get a resulting random > number, like so: > > sgambino-m1:~/vnv_for_pip > get_random > 0.0259274305036 > > However, if I try to import the get_random package into a python REPL I do > not see > a complete list of what is in the package. I only see the following: > > >>> dir(get_random) > >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > > but I was expecting to see: > > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'get_random', 'main', 'print_random', 'random'] > > If I try to import the get_random package into a script and run the script, > I get the following error: > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > Traceback (most recent call last): > File "./try_get_random.py", line 5, in > get_random.print_random() > AttributeError: 'module' object has no attribute 'print_random' > > Here is some more detail from the REPL that may give a clue. I'm wondering > if there is something in the setup.py that I haven't > defined correctly or not defined at all. I could share that if someone > thinks it is worth a look. The setup.py that I started with > was the one that is provided from https://github.com/pypa/sampleproject > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import get_random > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > >>> print(get_random.__file__) > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > >>> print(get_random.__package__) > None > >>> print(get_random.__path__) > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > If you have bothered to read this far, I hope this has made some sense and > I thank you for any ideas you may be willing to share! > Steve Gambino > -- > Best, > Steve > Hello friends, > I'm attempting to learn how to create a pip installable package. So far > the attempt has been relatively successful but for one nagging issue. I'm > hoping if I describe the issue here clearly enough that someone can offer > pointers to help me get to a resolution. > I've created the package (named get_random) successfully with setuptools > and have been able to do a pip install of it in a virtualenv. > The package "get_random" contains a trivial program also named > "get_random". The program, "get_random", imports one module, 'random', and > it has the functions, main(), get_random() and print_random(). After the > pip install of the get_random package, I can call the get_random program > from the command line in the virtualenv and get the expected results. In > otherwords, if I run the following in a terminal I get a resulting random > number, like so: > sgambino-m1:~/vnv_for_pip > get_random > 0.0259274305036 > However, if I try to import the get_random package into a python REPL I do > not see > a complete list of what is in the package. I only see the following: > >>> dir(get_random) > >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > '__path__'] > > but I was expecting to see: > > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'get_random', 'main', 'print_random', 'random'] > > If I try to import the get_random package into a script and run the > script, I get the following error: > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > Traceback (most recent call last): > ** File "./try_get_random.py", line 5, in > ****** get_random.print_random() > AttributeError: 'module' object has no attribute 'print_random' > > Here is some more detail from the REPL that may give a clue.** I'm > wondering if there is something in the setup.py that I haven't > defined correctly or not defined at all. I could share that if someone > thinks it is worth a look. The setup.py that I started with > was the one that is provided from [1]https://github.com/pypa/sampleproject > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import get_random > >>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > >>> print(get_random.__file__) > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > >>> print(get_random.__package__) > None > >>> print(get_random.__path__) > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > If you have bothered to read this far, I hope this has made some sense and > I thank you for any ideas you may be willing to share! > Steve Gambino > -- > Best,** > Steve > > References > > Visible links > 1. https://github.com/pypa/sampleproject > From stevegambino at gmail.com Thu Nov 2 01:07:49 2017 From: stevegambino at gmail.com (Steve Gambino) Date: Thu, 02 Nov 2017 05:07:49 +0000 Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: <1509588459.712518936@apps.rackspace.com> References: <1509588459.712518936@apps.rackspace.com> Message-ID: Hi David, Thank you for your questions. My answers are inline below. I've made the code available here so that you can look at the setup.py See https://github.com/sgambino/project-random I was a little confused reading your description, mainly because I wasn't sure when you said "package" whether you meant a distributable unit of Python code with a setup.py file, or whether you meant "an importable directory on sys.path containing an __init__.py file". > I see what you mean how my use of terms was confusing. I should have said a > distributable unit of Python code with a setup.py file Is there an importable package directory named "get_random" containing an __init__.py file? Or is there instead a get_random.py module? > Yes, there was an importable package directory named "get_random". Note that > since the original post, I renamed the distributable unit to "sample_random" and > the importable package directory to "try_random" If you have an importable package directory named get_random, then the behavior you saw is expected. When you import a package, the only names you see in that package are the ones defined (or imported into) the __init__.py file itself. To see anything in any other module inside that package you have to import that explicity, in your main program file or in the __init__.py file. Which form does your get_random program take? There are at least two ways to distribute Python scripts, one that uses setuptools and console entry points, and one doesn't. > The form of the program uses setuptools and console entry points. This is > the topic where I think my understanding is the weakest and need help with Yes, if you shared your full setup.py file with us, that would probably answer those questions and more, and would be helpful in diagnosing your problem. If you would share the full layout of your distributable package files, that would help too. > Yes, of course. See https://github.com/sgambino/project-random > And note that as mentioned earlier, I renamed the distributable unit from > to "sample_random" and the python package to "try_random" > > I reported earlier that after doing a pip install, I could run the program from > command line but if I tried to import the package into a script or into the > python REPL itself that I could not see the complete list of the package > so as to be able call its functions. It appears my issue was with the > way I was importing it into the namespace. I was declaring "import sample_random" > However, in the IRC channel, James (jwhisnant) was helping me, and he declared the > import in this form: "from sample_random import try_random" This appears > to have resolved the issue. I would like to better understand why so that > I do not repeat this behavior in the future. I suspect it may be with the > way I declared the "entry_points" in the setup.py I think need a better understanding > of entry points in general and also a clearer understanding of the semantic elements of the > form of how they are specified in the setup.py I used the example setup.py as referenced > in the tutorials at https://packaging.python.org/ There seems to be ample documentation > and commentary in the setup.py concerning entry points but it is still taking awhile for > it to become clear enough in my understanding so that I can confidently say, I truly > understand. :-) > > Thanks, > Steve Gambino On Wed, Nov 1, 2017 at 10:17 PM David Handy wrote: > Hi Steve - > > > > I was a little confused reading your description, mainly because I > wasn't > sure when you said "package" whether you meant a distributable unit of > Python code with a setup.py file, or whether you meant "an importable > directory on sys.path containing an __init__.py file". > > > > Is there an importable package directory named "get_random" containing > an > __init__.py file? Or is there instead a get_random.py module? > > > > If you have an importable package directory named get_random, then the > behavior you saw is expected. When you import a package, the only names > you see in that package are the ones defined (or imported into) the > __init__.py file itself. To see anything in any other module inside that > package you have to import that explicity, in your main program file or > in > the __init__.py file. > > > > Which form does your get_random program take? There are at least two > ways > to distribute Python scripts, one that uses setuptools and console entry > points, and one doesn't. > > > > Yes, if you shared your full setup.py file with us, that would probably > answer those questions and more, and would be helpful in diagnosing your > problem. If you would share the full layout of your distributable > package > files, that would help too. > > > > Thanks, > > David H > > > > > > On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > said: > > > _______________________________________________ > > TriZPUG mailing list > > TriZPUG at python.org > > https://mail.python.org/mailman/listinfo/trizpug > > http://tripython.org is the Triangle Python Users Group > > Hello friends, > > > > I'm attempting to learn how to create a pip installable package. So > far > the > > attempt has been relatively successful but for one nagging issue. I'm > > hoping if I describe the issue here clearly enough that someone can > offer > > pointers to help me get to a resolution. > > > > I've created the package (named get_random) successfully with > setuptools > > and have been able to do a pip install of it in a virtualenv. > > > > The package "get_random" contains a trivial program also named > > "get_random". The program, "get_random", imports one module, 'random', > and > > it has the functions, main(), get_random() and print_random(). After > the > > pip install of the get_random package, I can call the get_random > program > > from the command line in the virtualenv and get the expected results. > In > > otherwords, if I run the following in a terminal I get a resulting > random > > number, like so: > > > > sgambino-m1:~/vnv_for_pip > get_random > > 0.0259274305036 > > > > However, if I try to import the get_random package into a python REPL > I > do > > not see > > a complete list of what is in the package. I only see the following: > > > > >>> dir(get_random) > > >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > '__path__'] > > > > but I was expecting to see: > > > > >>> dir(get_random) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > 'get_random', 'main', 'print_random', 'random'] > > > > If I try to import the get_random package into a script and run the > script, > > I get the following error: > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > Traceback (most recent call last): > > File "./try_get_random.py", line 5, in > > get_random.print_random() > > AttributeError: 'module' object has no attribute 'print_random' > > > > Here is some more detail from the REPL that may give a clue. I'm > wondering > > if there is something in the setup.py that I haven't > > defined correctly or not defined at all. I could share that if someone > > thinks it is worth a look. The setup.py that I started with > > was the one that is provided from > https://github.com/pypa/sampleproject > > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import get_random > > >>> dir(get_random) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > '__path__'] > > >>> print(get_random.__file__) > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > >>> print(get_random.__package__) > > None > > >>> print(get_random.__path__) > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > > If you have bothered to read this far, I hope this has made some sense > and > > I thank you for any ideas you may be willing to share! > > Steve Gambino > > -- > > Best, > > Steve > > Hello friends, > > I'm attempting to learn how to create a pip installable package. So > far > > the attempt has been relatively successful but for one nagging issue. > I'm > > hoping if I describe the issue here clearly enough that someone can > offer > > pointers to help me get to a resolution. > > I've created the package (named get_random) successfully with > setuptools > > and have been able to do a pip install of it in a virtualenv. > > The package "get_random" contains a trivial program also named > > "get_random". The program, "get_random", imports one module, 'random', > and > > it has the functions, main(), get_random() and print_random(). After > the > > pip install of the get_random package, I can call the get_random > program > > from the command line in the virtualenv and get the expected results. > In > > otherwords, if I run the following in a terminal I get a resulting > random > > number, like so: > > sgambino-m1:~/vnv_for_pip > get_random > > 0.0259274305036 > > However, if I try to import the get_random package into a python REPL > I > do > > not see > > a complete list of what is in the package. I only see the following: > > >>> dir(get_random) > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > '__path__'] > > > > but I was expecting to see: > > > > >>> dir(get_random) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > 'get_random', 'main', 'print_random', 'random'] > > > > If I try to import the get_random package into a script and run the > > script, I get the following error: > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > Traceback (most recent call last): > > ** File "./try_get_random.py", line 5, in > > ****** get_random.print_random() > > AttributeError: 'module' object has no attribute 'print_random' > > > > Here is some more detail from the REPL that may give a clue.** I'm > > wondering if there is something in the setup.py that I haven't > > defined correctly or not defined at all. I could share that if someone > > thinks it is worth a look. The setup.py that I started with > > was the one that is provided from > [1]https://github.com/pypa/sampleproject > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import get_random > > >>> dir(get_random) > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > '__path__'] > > >>> print(get_random.__file__) > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > >>> print(get_random.__package__) > > None > > >>> print(get_random.__path__) > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > If you have bothered to read this far, I hope this has made some sense > and > > I thank you for any ideas you may be willing to share! > > Steve Gambino > > -- > > Best,** > > Steve > > > > References > > > > Visible links > > 1. https://github.com/pypa/sampleproject > > > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > -- Best, Steve -------------- next part -------------- Hi David, Thank you for your questions.** My answers are inline below.** I've made the code available here so that you can look at the setup.py See [1]https://github.com/sgambino/project-random I was a little confused reading your description, mainly because I wasn't ** **sure when you said "package" whether you meant a distributable unit of ** **Python code with a setup.py file, or whether you meant "an importable ** **directory on sys.path containing an __init__.py file". > I see what you mean how my use of terms was confusing. I should have said a > distributable unit of Python code with a setup.py file ** **Is there an importable package directory named "get_random" containing an ** **__init__.py file? Or is there instead a get_random.py module? > Yes, there was an importable package directory named "get_random".** Note that > since the original post, I renamed the distributable unit to "sample_random" and > the importable package directory to "try_random" ** **If you have an importable package directory named get_random, then the ** **behavior you saw is expected. When you import a package, the only names ** **you see in that package are the ones defined (or imported into) the ** **__init__.py file itself. To see anything in any other module inside that ** **package you have to import that explicity, in your main program file or in ** **the __init__.py file. ** **Which form does your get_random program take? There are at least two ways ** **to distribute Python scripts, one that uses setuptools and console entry ** **points, and one doesn't. > The form of the program uses setuptools and console entry points. This is > the topic where I think my understanding is the weakest and need help with ** **Yes, if you shared your full setup.py file with us, that would probably ** **answer those questions and more, and would be helpful in diagnosing your ** **problem. If you would share the full layout of your distributable package ** **files, that would help too. > Yes, of course. See [2]https://github.com/sgambino/project-random > And note that as mentioned earlier, I renamed the distributable unit from >** to "sample_random" and the python package to "try_random" > > I reported earlier that after doing a pip install, I could run the program from > command line but if I tried to import the package into a script or into the > python REPL itself that I could not see the complete list of the package > so as to be able call its functions.**** It appears my issue was with the > way I was importing it into the namespace.** I was declaring "import sample_random" > However, in the IRC channel, James (jwhisnant) was helping me, and he declared the > import in this form: "from sample_random import try_random"****** This appears > to have resolved the issue.** I would like to better understand why so that > I do not repeat this behavior in the future.** I suspect it may be with the > way I declared the "entry_points" in the setup.py**** I think need a better understanding > of entry points in general and also a clearer understanding of the semantic elements of the > form of how they are specified in the setup.py**** I used the example setup.py as referenced > in the tutorials at [3]https://packaging.python.org/**** There seems to be ample documentation > and commentary in the setup.py concerning entry points but it is still taking awhile for > it to become clear enough in my understanding so that I can confidently say, I truly > understand. :-) > > Thanks, > Steve Gambino On Wed, Nov 1, 2017 at 10:17 PM David Handy <[4]david at handysoftware.com> wrote: ** **Hi Steve - ** **I was a little confused reading your description, mainly because I wasn't ** **sure when you said "package" whether you meant a distributable unit of ** **Python code with a setup.py file, or whether you meant "an importable ** **directory on sys.path containing an __init__.py file". ** **Is there an importable package directory named "get_random" containing an ** **__init__.py file? Or is there instead a get_random.py module? ** **If you have an importable package directory named get_random, then the ** **behavior you saw is expected. When you import a package, the only names ** **you see in that package are the ones defined (or imported into) the ** **__init__.py file itself. To see anything in any other module inside that ** **package you have to import that explicity, in your main program file or in ** **the __init__.py file. ** **Which form does your get_random program take? There are at least two ways ** **to distribute Python scripts, one that uses setuptools and console entry ** **points, and one doesn't. ** **Yes, if you shared your full setup.py file with us, that would probably ** **answer those questions and more, and would be helpful in diagnosing your ** **problem. If you would share the full layout of your distributable package ** **files, that would help too. ** **Thanks, ** **David H ** **On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" ** **<[5]stevegambino at gmail.com> said: ** **> _______________________________________________ ** **> TriZPUG mailing list ** **> [6]TriZPUG at python.org ** **> [7]https://mail.python.org/mailman/listinfo/trizpug ** **> [8]http://tripython.org is the Triangle Python Users Group ** **> Hello friends, ** **> ** **> I'm attempting to learn how to create a pip installable package. So far ** **the ** **> attempt has been relatively successful but for one nagging issue. I'm ** **> hoping if I describe the issue here clearly enough that someone can ** **offer ** **> pointers to help me get to a resolution. ** **> ** **> I've created the package (named get_random) successfully with setuptools ** **> and have been able to do a pip install of it in a virtualenv. ** **> ** **> The package "get_random" contains a trivial program also named ** **> "get_random". The program, "get_random", imports one module, 'random', ** **and ** **> it has the functions, main(), get_random() and print_random(). After the ** **> pip install of the get_random package, I can call the get_random program ** **> from the command line in the virtualenv and get the expected results. In ** **> otherwords, if I run the following in a terminal I get a resulting ** **random ** **> number, like so: ** **> ** **> sgambino-m1:~/vnv_for_pip > get_random ** **> 0.0259274305036 ** **> ** **> However, if I try to import the get_random package into a python REPL I ** **do ** **> not see ** **> a complete list of what is in the package. I only see the following: ** **> ** **> >>> dir(get_random) ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> '__path__'] ** **> ** **> but I was expecting to see: ** **> ** **> >>> dir(get_random) ** **> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> 'get_random', 'main', 'print_random', 'random'] ** **> ** **> If I try to import the get_random package into a script and run the ** **script, ** **> I get the following error: ** **> ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> Traceback (most recent call last): ** **> File "./try_get_random.py", line 5, in ** **> get_random.print_random() ** **> AttributeError: 'module' object has no attribute 'print_random' ** **> ** **> Here is some more detail from the REPL that may give a clue. I'm ** **wondering ** **> if there is something in the setup.py that I haven't ** **> defined correctly or not defined at all. I could share that if someone ** **> thinks it is worth a look. The setup.py that I started with ** **> was the one that is provided from [9]https://github.com/pypa/sampleproject ** **> ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin ** **> Type "help", "copyright", "credits" or "license" for more information. ** **> >>> import get_random ** **> >>> dir(get_random) ** **> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> '__path__'] ** **> >>> print(get_random.__file__) ** **> ** **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> >>> print(get_random.__package__) ** **> None ** **> >>> print(get_random.__path__) ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> ** **> If you have bothered to read this far, I hope this has made some sense ** **and ** **> I thank you for any ideas you may be willing to share! ** **> Steve Gambino ** **> -- ** **> Best, ** **> Steve ** **> Hello friends, ** **> I'm attempting to learn how to create a pip installable package. So far ** **> the attempt has been relatively successful but for one nagging issue. ** **I'm ** **> hoping if I describe the issue here clearly enough that someone can ** **offer ** **> pointers to help me get to a resolution. ** **> I've created the package (named get_random) successfully with setuptools ** **> and have been able to do a pip install of it in a virtualenv. ** **> The package "get_random" contains a trivial program also named ** **> "get_random". The program, "get_random", imports one module, 'random', ** **and ** **> it has the functions, main(), get_random() and print_random(). After the ** **> pip install of the get_random package, I can call the get_random program ** **> from the command line in the virtualenv and get the expected results. In ** **> otherwords, if I run the following in a terminal I get a resulting ** **random ** **> number, like so: ** **> sgambino-m1:~/vnv_for_pip > get_random ** **> 0.0259274305036 ** **> However, if I try to import the get_random package into a python REPL I ** **do ** **> not see ** **> a complete list of what is in the package. I only see the following: ** **> >>> dir(get_random) ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> '__path__'] ** **> ** **> but I was expecting to see: ** **> ** **> >>> dir(get_random) ** **> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> 'get_random', 'main', 'print_random', 'random'] ** **> ** **> If I try to import the get_random package into a script and run the ** **> script, I get the following error: ** **> ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> Traceback (most recent call last): ** **> ** File "./try_get_random.py", line 5, in ** **> ****** get_random.print_random() ** **> AttributeError: 'module' object has no attribute 'print_random' ** **> ** **> Here is some more detail from the REPL that may give a clue.** I'm ** **> wondering if there is something in the setup.py that I haven't ** **> defined correctly or not defined at all. I could share that if someone ** **> thinks it is worth a look. The setup.py that I started with ** **> was the one that is provided from ** **[1][10]https://github.com/pypa/sampleproject ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin ** **> Type "help", "copyright", "credits" or "license" for more information. ** **> >>> import get_random ** **> >>> dir(get_random) ** **> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> '__path__'] ** **> >>> print(get_random.__file__) ** **> ** **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> >>> print(get_random.__package__) ** **> None ** **> >>> print(get_random.__path__) ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> If you have bothered to read this far, I hope this has made some sense ** **and ** **> I thank you for any ideas you may be willing to share! ** **> Steve Gambino ** **> -- ** **> Best,** ** **> Steve ** **> ** **> References ** **> ** **> Visible links ** **> 1. [11]https://github.com/pypa/sampleproject ** **> _______________________________________________ TriZPUG mailing list [12]TriZPUG at python.org [13]https://mail.python.org/mailman/listinfo/trizpug [14]http://tripython.org is the Triangle Python Users Group -- Best,** Steve References Visible links 1. https://github.com/sgambino/project-random 2. https://github.com/sgambino/project-random 3. https://packaging.python.org/ 4. mailto:david at handysoftware.com 5. mailto:stevegambino at gmail.com 6. mailto:TriZPUG at python.org 7. https://mail.python.org/mailman/listinfo/trizpug 8. http://tripython.org/ 9. https://github.com/pypa/sampleproject 10. https://github.com/pypa/sampleproject 11. https://github.com/pypa/sampleproject 12. mailto:TriZPUG at python.org 13. https://mail.python.org/mailman/listinfo/trizpug 14. http://tripython.org/ From david at handysoftware.com Thu Nov 2 10:40:08 2017 From: david at handysoftware.com (David Handy) Date: Thu, 2 Nov 2017 10:40:08 -0400 (EDT) Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: References: <1509588459.712518936@apps.rackspace.com> Message-ID: <1509633608.63253104@apps.rackspace.com> Hi Steve - Actually people refer to a "distributable unit of Python code" as a "package" all the time, it was only confusing to me in this context because we were switching back and forth talking about both kinds of packages. :) Here's what I did: git clone [ https://github.com/sgambino/project-random.git ]( https://github.com/sgambino/project-random.git ) virtualenv -p python3 env source env/bin/activate pip install -e project-random/ sample_random Which printed a random number: 0.5678855151148471 So far so good! Now for importing it: python # This just imports the __init__.py file in the sample_random directory >>> import sample_random # This imports the try_random module from the sample_random directory >>> from sample_random import try_random # This of course calls the main() function in the try_random module >>> try_random.main() 0.20974369539964732 This is all standard behavior for Python "packages" (importable directories) whether or not pip/virtualenv is involved. As for entry points - notice in your setup.py file, you have this parameter in your call to setup(): entry_points={ 'console_scripts': [ 'sample_random=sample_random.try_random:main', ], } What this means is: Tell setuptools to create a list of scripts (currently a list of just one). Create a script named "sample_random" that imports the try_random module from the sample_random package and calls the main() function to run it. If you look in the bin directory of the virtual environment where pip install this "package" (distribution of code), you see that setuptools created a file named sample_random with these contents: #!/home/david/temp/env/bin/python3 # EASY-INSTALL-ENTRY-SCRIPT: 'sample-random','console_scripts','sample_random' __requires__ = 'sample-random' import re import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit( load_entry_point('sample-random', 'console_scripts', 'sample_random')() ) Notice at the top of the file is a #! line that points to the python interpreter for this virtual environment. The rest of the gobbledygook loads your loads your try_random module and runs that main function in such a way that it looks like it got run from the command line. It uses metadata installed by setuptools in the site-packages of your virtual environment to find the entry point, and to know which package and module to load and which function to run. I hope this helps. I gotta get back to work now! David H On Thursday, November 2, 2017 1:07am, "Steve Gambino" said: > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > Hi David, > Thank you for your questions. My answers are inline below. I've made > the code available here so that you can look at the setup.py > See https://github.com/sgambino/project-random > > I was a little confused reading your description, mainly because I wasn't > sure when you said "package" whether you meant a distributable unit of > Python code with a setup.py file, or whether you meant "an importable > directory on sys.path containing an __init__.py file". > > > > I see what you mean how my use of terms was confusing. I should have said > a > > distributable unit of Python code with a setup.py file > > > > Is there an importable package directory named "get_random" containing an > __init__.py file? Or is there instead a get_random.py module? > > > Yes, there was an importable package directory named "get_random". Note > that > > since the original post, I renamed the distributable unit to > "sample_random" and > > the importable package directory to "try_random" > > If you have an importable package directory named get_random, then the > behavior you saw is expected. When you import a package, the only names > you see in that package are the ones defined (or imported into) the > __init__.py file itself. To see anything in any other module inside that > package you have to import that explicity, in your main program file or > in > the __init__.py file. > > > > Which form does your get_random program take? There are at least two ways > to distribute Python scripts, one that uses setuptools and console entry > points, and one doesn't. > > > The form of the program uses setuptools and console entry points. This is > > the topic where I think my understanding is the weakest and need help with > > Yes, if you shared your full setup.py file with us, that would probably > answer those questions and more, and would be helpful in diagnosing your > problem. If you would share the full layout of your distributable package > files, that would help too. > > > Yes, of course. See https://github.com/sgambino/project-random > > And note that as mentioned earlier, I renamed the distributable unit from > > to "sample_random" and the python package to "try_random" > > > > I reported earlier that after doing a pip install, I could run the > program from > > command line but if I tried to import the package into a script or into > the > > python REPL itself that I could not see the complete list of the package > > so as to be able call its functions. It appears my issue was with the > > way I was importing it into the namespace. I was declaring "import > sample_random" > > However, in the IRC channel, James (jwhisnant) was helping me, and he > declared the > > import in this form: "from sample_random import try_random" This > appears > > to have resolved the issue. I would like to better understand why so that > > I do not repeat this behavior in the future. I suspect it may be with the > > way I declared the "entry_points" in the setup.py I think need a better > understanding > > of entry points in general and also a clearer understanding of the > semantic elements of the > > form of how they are specified in the setup.py I used the example > setup.py as referenced > > in the tutorials at https://packaging.python.org/ There seems to be > ample documentation > > and commentary in the setup.py concerning entry points but it is still > taking awhile for > > it to become clear enough in my understanding so that I can confidently > say, I truly > > understand. :-) > > > > Thanks, > > Steve Gambino > > On Wed, Nov 1, 2017 at 10:17 PM David Handy > wrote: > > > Hi Steve - > > > > > > > > I was a little confused reading your description, mainly because I > > wasn't > > sure when you said "package" whether you meant a distributable unit of > > Python code with a setup.py file, or whether you meant "an importable > > directory on sys.path containing an __init__.py file". > > > > > > > > Is there an importable package directory named "get_random" containing > > an > > __init__.py file? Or is there instead a get_random.py module? > > > > > > > > If you have an importable package directory named get_random, then the > > behavior you saw is expected. When you import a package, the only names > > you see in that package are the ones defined (or imported into) the > > __init__.py file itself. To see anything in any other module inside that > > package you have to import that explicity, in your main program file or > > in > > the __init__.py file. > > > > > > > > Which form does your get_random program take? There are at least two > > ways > > to distribute Python scripts, one that uses setuptools and console entry > > points, and one doesn't. > > > > > > > > Yes, if you shared your full setup.py file with us, that would probably > > answer those questions and more, and would be helpful in diagnosing your > > problem. If you would share the full layout of your distributable > > package > > files, that would help too. > > > > > > > > Thanks, > > > > David H > > > > > > > > > > > > On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > > said: > > > > > _______________________________________________ > > > TriZPUG mailing list > > > TriZPUG at python.org > > > https://mail.python.org/mailman/listinfo/trizpug > > > http://tripython.org is the Triangle Python Users Group > > > Hello friends, > > > > > > I'm attempting to learn how to create a pip installable package. So > > far > > the > > > attempt has been relatively successful but for one nagging issue. > I'm > > > hoping if I describe the issue here clearly enough that someone can > > offer > > > pointers to help me get to a resolution. > > > > > > I've created the package (named get_random) successfully with > > setuptools > > > and have been able to do a pip install of it in a virtualenv. > > > > > > The package "get_random" contains a trivial program also named > > > "get_random". The program, "get_random", imports one module, > 'random', > > and > > > it has the functions, main(), get_random() and print_random(). After > > the > > > pip install of the get_random package, I can call the get_random > > program > > > from the command line in the virtualenv and get the expected > results. > > In > > > otherwords, if I run the following in a terminal I get a resulting > > random > > > number, like so: > > > > > > sgambino-m1:~/vnv_for_pip > get_random > > > 0.0259274305036 > > > > > > However, if I try to import the get_random package into a python > REPL > > I > > do > > > not see > > > a complete list of what is in the package. I only see the following: > > > > > > >>> dir(get_random) > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > > > '__path__'] > > > > > > but I was expecting to see: > > > > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > If I try to import the get_random package into a script and run the > > script, > > > I get the following error: > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > Traceback (most recent call last): > > > File "./try_get_random.py", line 5, in > > > get_random.print_random() > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > Here is some more detail from the REPL that may give a clue. I'm > > wondering > > > if there is something in the setup.py that I haven't > > > defined correctly or not defined at all. I could share that if > someone > > > thinks it is worth a look. The setup.py that I started with > > > was the one that is provided from > > https://github.com/pypa/sampleproject > > > > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > > Type "help", "copyright", "credits" or "license" for more > information. > > > >>> import get_random > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > '__path__'] > > > >>> print(get_random.__file__) > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > >>> print(get_random.__package__) > > > None > > > >>> print(get_random.__path__) > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > > > > If you have bothered to read this far, I hope this has made some > sense > > and > > > I thank you for any ideas you may be willing to share! > > > Steve Gambino > > > -- > > > Best, > > > Steve > > > Hello friends, > > > I'm attempting to learn how to create a pip installable package. So > > far > > > the attempt has been relatively successful but for one nagging > issue. > > I'm > > > hoping if I describe the issue here clearly enough that someone can > > offer > > > pointers to help me get to a resolution. > > > I've created the package (named get_random) successfully with > > setuptools > > > and have been able to do a pip install of it in a virtualenv. > > > The package "get_random" contains a trivial program also named > > > "get_random". The program, "get_random", imports one module, > 'random', > > and > > > it has the functions, main(), get_random() and print_random(). After > > the > > > pip install of the get_random package, I can call the get_random > > program > > > from the command line in the virtualenv and get the expected > results. > > In > > > otherwords, if I run the following in a terminal I get a resulting > > random > > > number, like so: > > > sgambino-m1:~/vnv_for_pip > get_random > > > 0.0259274305036 > > > However, if I try to import the get_random package into a python > REPL > > I > > do > > > not see > > > a complete list of what is in the package. I only see the following: > > > >>> dir(get_random) > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > > > '__package__', > > > '__path__'] > > > > > > but I was expecting to see: > > > > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > If I try to import the get_random package into a script and run the > > > script, I get the following error: > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > Traceback (most recent call last): > > > ** File "./try_get_random.py", line 5, in > > > ****** get_random.print_random() > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > Here is some more detail from the REPL that may give a clue.** I'm > > > wondering if there is something in the setup.py that I haven't > > > defined correctly or not defined at all. I could share that if > someone > > > thinks it is worth a look. The setup.py that I started with > > > was the one that is provided from > > [1]https://github.com/pypa/sampleproject > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > > Type "help", "copyright", "credits" or "license" for more > information. > > > >>> import get_random > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > '__path__'] > > > >>> print(get_random.__file__) > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > >>> print(get_random.__package__) > > > None > > > >>> print(get_random.__path__) > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > If you have bothered to read this far, I hope this has made some > sense > > and > > > I thank you for any ideas you may be willing to share! > > > Steve Gambino > > > -- > > > Best,** > > > Steve > > > > > > References > > > > > > Visible links > > > 1. https://github.com/pypa/sampleproject > > > > > _______________________________________________ > > TriZPUG mailing list > > TriZPUG at python.org > > https://mail.python.org/mailman/listinfo/trizpug > > http://tripython.org is the Triangle Python Users Group > > > -- > Best, > Steve > Hi David, > Thank you for your questions.** My answers are inline below.** I've made > the code available here so that you can look at the setup.py > See [1]https://github.com/sgambino/project-random > I was a little confused reading your description, mainly because I wasn't > ** **sure when you said "package" whether you meant a distributable unit > of > ** **Python code with a setup.py file, or whether you meant "an importable > ** **directory on sys.path containing an __init__.py file". > > I see what you mean how my use of terms was confusing. I should have > said a > > distributable unit of Python code with a setup.py file > > ** **Is there an importable package directory named "get_random" > containing an > ** **__init__.py file? Or is there instead a get_random.py module? > > > Yes, there was an importable package directory named "get_random".** > Note that > > since the original post, I renamed the distributable unit to > "sample_random" and > > the importable package directory to "try_random" > ** **If you have an importable package directory named get_random, then > the > ** **behavior you saw is expected. When you import a package, the only > names > ** **you see in that package are the ones defined (or imported into) the > ** **__init__.py file itself. To see anything in any other module inside > that > ** **package you have to import that explicity, in your main program file > or in > ** **the __init__.py file. > > ** **Which form does your get_random program take? There are at least two > ways > ** **to distribute Python scripts, one that uses setuptools and console > entry > ** **points, and one doesn't. > > > The form of the program uses setuptools and console entry points. This > is > > the topic where I think my understanding is the weakest and need help > with > ** **Yes, if you shared your full setup.py file with us, that would > probably > ** **answer those questions and more, and would be helpful in diagnosing > your > ** **problem. If you would share the full layout of your distributable > package > ** **files, that would help too. > > Yes, of course. See [2]https://github.com/sgambino/project-random > > And note that as mentioned earlier, I renamed the distributable unit > from > >** to "sample_random" and the python package to "try_random" > > > > I reported earlier that after doing a pip install, I could run the > program from > > command line but if I tried to import the package into a script or into > the > > python REPL itself that I could not see the complete list of the package > > so as to be able call its functions.**** It appears my issue was with > the > > way I was importing it into the namespace.** I was declaring "import > sample_random" > > However, in the IRC channel, James (jwhisnant) was helping me, and he > declared the > > import in this form: "from sample_random import try_random"****** This > appears > > to have resolved the issue.** I would like to better understand why so > that > > I do not repeat this behavior in the future.** I suspect it may be with > the > > way I declared the "entry_points" in the setup.py**** I think need a > better understanding > > of entry points in general and also a clearer understanding of the > semantic elements of the > > form of how they are specified in the setup.py**** I used the example > setup.py as referenced > > in the tutorials at [3]https://packaging.python.org/**** There seems to > be ample documentation > > and commentary in the setup.py concerning entry points but it is still > taking awhile for > > it to become clear enough in my understanding so that I can confidently > say, I truly > > understand. :-) > > > > Thanks, > > Steve Gambino > On Wed, Nov 1, 2017 at 10:17 PM David Handy <[4]david at handysoftware.com> > wrote: > > ** **Hi Steve - > > ** **I was a little confused reading your description, mainly because I > wasn't > ** **sure when you said "package" whether you meant a distributable unit > of > ** **Python code with a setup.py file, or whether you meant "an > importable > ** **directory on sys.path containing an __init__.py file". > > ** **Is there an importable package directory named "get_random" > containing an > ** **__init__.py file? Or is there instead a get_random.py module? > > ** **If you have an importable package directory named get_random, then > the > ** **behavior you saw is expected. When you import a package, the only > names > ** **you see in that package are the ones defined (or imported into) the > ** **__init__.py file itself. To see anything in any other module inside > that > ** **package you have to import that explicity, in your main program > file or in > ** **the __init__.py file. > > ** **Which form does your get_random program take? There are at least > two ways > ** **to distribute Python scripts, one that uses setuptools and console > entry > ** **points, and one doesn't. > > ** **Yes, if you shared your full setup.py file with us, that would > probably > ** **answer those questions and more, and would be helpful in diagnosing > your > ** **problem. If you would share the full layout of your distributable > package > ** **files, that would help too. > > ** **Thanks, > > ** **David H > > ** **On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > ** **<[5]stevegambino at gmail.com> said: > > ** **> _______________________________________________ > ** **> TriZPUG mailing list > ** **> [6]TriZPUG at python.org > ** **> [7]https://mail.python.org/mailman/listinfo/trizpug > ** **> [8]http://tripython.org is the Triangle Python Users Group > ** **> Hello friends, > ** **> > ** **> I'm attempting to learn how to create a pip installable package. > So far > ** **the > ** **> attempt has been relatively successful but for one nagging issue. > I'm > ** **> hoping if I describe the issue here clearly enough that someone > can > ** **offer > ** **> pointers to help me get to a resolution. > ** **> > ** **> I've created the package (named get_random) successfully with > setuptools > ** **> and have been able to do a pip install of it in a virtualenv. > ** **> > ** **> The package "get_random" contains a trivial program also named > ** **> "get_random". The program, "get_random", imports one module, > 'random', > ** **and > ** **> it has the functions, main(), get_random() and print_random(). > After the > ** **> pip install of the get_random package, I can call the get_random > program > ** **> from the command line in the virtualenv and get the expected > results. In > ** **> otherwords, if I run the following in a terminal I get a > resulting > ** **random > ** **> number, like so: > ** **> > ** **> sgambino-m1:~/vnv_for_pip > get_random > ** **> 0.0259274305036 > ** **> > ** **> However, if I try to import the get_random package into a python > REPL I > ** **do > ** **> not see > ** **> a complete list of what is in the package. I only see the > following: > ** **> > ** **> >>> dir(get_random) > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> > ** **> but I was expecting to see: > ** **> > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> 'get_random', 'main', 'print_random', 'random'] > ** **> > ** **> If I try to import the get_random package into a script and run > the > ** **script, > ** **> I get the following error: > ** **> > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > ** **> Traceback (most recent call last): > ** **> File "./try_get_random.py", line 5, in > ** **> get_random.print_random() > ** **> AttributeError: 'module' object has no attribute 'print_random' > ** **> > ** **> Here is some more detail from the REPL that may give a clue. I'm > ** **wondering > ** **> if there is something in the setup.py that I haven't > ** **> defined correctly or not defined at all. I could share that if > someone > ** **> thinks it is worth a look. The setup.py that I started with > ** **> was the one that is provided from > [9]https://github.com/pypa/sampleproject > ** **> > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > ** **> Type "help", "copyright", "credits" or "license" for more > information. > ** **> >>> import get_random > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> >>> print(get_random.__file__) > ** **> > ** > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > ** **> >>> print(get_random.__package__) > ** **> None > ** **> >>> print(get_random.__path__) > ** **> > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > ** **> > ** **> If you have bothered to read this far, I hope this has made some > sense > ** **and > ** **> I thank you for any ideas you may be willing to share! > ** **> Steve Gambino > ** **> -- > ** **> Best, > ** **> Steve > ** **> Hello friends, > ** **> I'm attempting to learn how to create a pip installable package. > So far > ** **> the attempt has been relatively successful but for one nagging > issue. > ** **I'm > ** **> hoping if I describe the issue here clearly enough that someone > can > ** **offer > ** **> pointers to help me get to a resolution. > ** **> I've created the package (named get_random) successfully with > setuptools > ** **> and have been able to do a pip install of it in a virtualenv. > ** **> The package "get_random" contains a trivial program also named > ** **> "get_random". The program, "get_random", imports one module, > 'random', > ** **and > ** **> it has the functions, main(), get_random() and print_random(). > After the > ** **> pip install of the get_random package, I can call the get_random > program > ** **> from the command line in the virtualenv and get the expected > results. In > ** **> otherwords, if I run the following in a terminal I get a > resulting > ** **random > ** **> number, like so: > ** **> sgambino-m1:~/vnv_for_pip > get_random > ** **> 0.0259274305036 > ** **> However, if I try to import the get_random package into a python > REPL I > ** **do > ** **> not see > ** **> a complete list of what is in the package. I only see the > following: > ** **> >>> dir(get_random) > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > ** **> '__package__', > ** **> '__path__'] > ** **> > ** **> but I was expecting to see: > ** **> > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> 'get_random', 'main', 'print_random', 'random'] > ** **> > ** **> If I try to import the get_random package into a script and run > the > ** **> script, I get the following error: > ** **> > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > ** **> Traceback (most recent call last): > ** **> ** File "./try_get_random.py", line 5, in > ** **> ****** get_random.print_random() > ** **> AttributeError: 'module' object has no attribute 'print_random' > ** **> > ** **> Here is some more detail from the REPL that may give a clue.** > I'm > ** **> wondering if there is something in the setup.py that I haven't > ** **> defined correctly or not defined at all. I could share that if > someone > ** **> thinks it is worth a look. The setup.py that I started with > ** **> was the one that is provided from > ** **[1][10]https://github.com/pypa/sampleproject > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > ** **> Type "help", "copyright", "credits" or "license" for more > information. > ** **> >>> import get_random > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> >>> print(get_random.__file__) > ** **> > ** > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > ** **> >>> print(get_random.__package__) > ** **> None > ** **> >>> print(get_random.__path__) > ** **> > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > ** **> If you have bothered to read this far, I hope this has made some > sense > ** **and > ** **> I thank you for any ideas you may be willing to share! > ** **> Steve Gambino > ** **> -- > ** **> Best,** > ** **> Steve > ** **> > ** **> References > ** **> > ** **> Visible links > ** **> 1. [11]https://github.com/pypa/sampleproject > ** **> > _______________________________________________ > TriZPUG mailing list > [12]TriZPUG at python.org > [13]https://mail.python.org/mailman/listinfo/trizpug > [14]http://tripython.org is the Triangle Python Users Group > > -- > Best,** > Steve > > References > > Visible links > 1. https://github.com/sgambino/project-random > 2. https://github.com/sgambino/project-random > 3. https://packaging.python.org/ > 4. mailto:david at handysoftware.com > 5. mailto:stevegambino at gmail.com > 6. mailto:TriZPUG at python.org > 7. https://mail.python.org/mailman/listinfo/trizpug > 8. http://tripython.org/ > 9. https://github.com/pypa/sampleproject > 10. https://github.com/pypa/sampleproject > 11. https://github.com/pypa/sampleproject > 12. mailto:TriZPUG at python.org > 13. https://mail.python.org/mailman/listinfo/trizpug > 14. http://tripython.org/ > -------------- next part -------------- Hi Steve - Actually people refer to a "distributable unit of Python code" as a "package" all the time, it was only confusing to me in this context because we were switching back and forth talking about both kinds of packages. :) Here's what I did: git clone [1]https://github.com/sgambino/project-random.git virtualenv -p python3 env source env/bin/activate pip install -e project-random/ sample_random Which printed a random number: 0.5678855151148471 So far so good! Now for importing it: python # This just imports the __init__.py file in the sample_random directory >>> import sample_random # This imports the try_random module from the sample_random directory >>> from sample_random import try_random # This of course calls the main() function in the try_random module >>> try_random.main() 0.20974369539964732 This is all standard behavior for Python "packages" (importable directories) whether or not pip/virtualenv is involved. As for entry points - notice in your setup.py file, you have this parameter in your call to setup(): entry_points={ 'console_scripts': [ 'sample_random=sample_random.try_random:main', ], } What this means is: Tell setuptools to create a list of scripts (currently a list of just one). Create a script named "sample_random" that imports the try_random module from the sample_random package and calls the main() function to run it. If you look in the bin directory of the virtual environment where pip install this "package" (distribution of code), you see that setuptools created a file named sample_random with these contents: #!/home/david/temp/env/bin/python3 # EASY-INSTALL-ENTRY-SCRIPT: 'sample-random','console_scripts','sample_random' __requires__ = 'sample-random' import re import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit( load_entry_point('sample-random', 'console_scripts', 'sample_random')() ) Notice at the top of the file is a #! line that points to the python interpreter for this virtual environment. The rest of the gobbledygook loads your loads your try_random module and runs that main function in such a way that it looks like it got run from the command line. It uses metadata installed by setuptools in the site-packages of your virtual environment to find the entry point, and to know which package and module to load and which function to run. I hope this helps. I gotta get back to work now! David H On Thursday, November 2, 2017 1:07am, "Steve Gambino" said: > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > Hi David, > Thank you for your questions. My answers are inline below. I've made > the code available here so that you can look at the setup.py > See https://github.com/sgambino/project-random > > I was a little confused reading your description, mainly because I wasn't > sure when you said "package" whether you meant a distributable unit of > Python code with a setup.py file, or whether you meant "an importable > directory on sys.path containing an __init__.py file". > > > > I see what you mean how my use of terms was confusing. I should have said > a > > distributable unit of Python code with a setup.py file > > > > Is there an importable package directory named "get_random" containing an > __init__.py file? Or is there instead a get_random.py module? > > > Yes, there was an importable package directory named "get_random". Note > that > > since the original post, I renamed the distributable unit to > "sample_random" and > > the importable package directory to "try_random" > > If you have an importable package directory named get_random, then the > behavior you saw is expected. When you import a package, the only names > you see in that package are the ones defined (or imported into) the > __init__.py file itself. To see anything in any other module inside that > package you have to import that explicity, in your main program file or > in > the __init__.py file. > > > > Which form does your get_random program take? There are at least two ways > to distribute Python scripts, one that uses setuptools and console entry > points, and one doesn't. > > > The form of the program uses setuptools and console entry points. This is > > the topic where I think my understanding is the weakest and need help with > > Yes, if you shared your full setup.py file with us, that would probably > answer those questions and more, and would be helpful in diagnosing your > problem. If you would share the full layout of your distributable package > files, that would help too. > > > Yes, of course. See https://github.com/sgambino/project-random > > And note that as mentioned earlier, I renamed the distributable unit from > > to "sample_random" and the python package to "try_random" > > > > I reported earlier that after doing a pip install, I could run the > program from > > command line but if I tried to import the package into a script or into > the > > python REPL itself that I could not see the complete list of the package > > so as to be able call its functions. It appears my issue was with the > > way I was importing it into the namespace. I was declaring "import > sample_random" > > However, in the IRC channel, James (jwhisnant) was helping me, and he > declared the > > import in this form: "from sample_random import try_random" This > appears > > to have resolved the issue. I would like to better understand why so that > > I do not repeat this behavior in the future. I suspect it may be with the > > way I declared the "entry_points" in the setup.py I think need a better > understanding > > of entry points in general and also a clearer understanding of the > semantic elements of the > > form of how they are specified in the setup.py I used the example > setup.py as referenced > > in the tutorials at https://packaging.python.org/ There seems to be > ample documentation > > and commentary in the setup.py concerning entry points but it is still > taking awhile for > > it to become clear enough in my understanding so that I can confidently > say, I truly > > understand. :-) > > > > Thanks, > > Steve Gambino > > On Wed, Nov 1, 2017 at 10:17 PM David Handy > wrote: > > > Hi Steve - > > > > > > > > I was a little confused reading your description, mainly because I > > wasn't > > sure when you said "package" whether you meant a distributable unit of > > Python code with a setup.py file, or whether you meant "an importable > > directory on sys.path containing an __init__.py file". > > > > > > > > Is there an importable package directory named "get_random" containing > > an > > __init__.py file? Or is there instead a get_random.py module? > > > > > > > > If you have an importable package directory named get_random, then the > > behavior you saw is expected. When you import a package, the only names > > you see in that package are the ones defined (or imported into) the > > __init__.py file itself. To see anything in any other module inside that > > package you have to import that explicity, in your main program file or > > in > > the __init__.py file. > > > > > > > > Which form does your get_random program take? There are at least two > > ways > > to distribute Python scripts, one that uses setuptools and console entry > > points, and one doesn't. > > > > > > > > Yes, if you shared your full setup.py file with us, that would probably > > answer those questions and more, and would be helpful in diagnosing your > > problem. If you would share the full layout of your distributable > > package > > files, that would help too. > > > > > > > > Thanks, > > > > David H > > > > > > > > > > > > On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > > said: > > > > > _______________________________________________ > > > TriZPUG mailing list > > > TriZPUG at python.org > > > https://mail.python.org/mailman/listinfo/trizpug > > > http://tripython.org is the Triangle Python Users Group > > > Hello friends, > > > > > > I'm attempting to learn how to create a pip installable package. So > > far > > the > > > attempt has been relatively successful but for one nagging issue. > I'm > > > hoping if I describe the issue here clearly enough that someone can > > offer > > > pointers to help me get to a resolution. > > > > > > I've created the package (named get_random) successfully with > > setuptools > > > and have been able to do a pip install of it in a virtualenv. > > > > > > The package "get_random" contains a trivial program also named > > > "get_random". The program, "get_random", imports one module, > 'random', > > and > > > it has the functions, main(), get_random() and print_random(). After > > the > > > pip install of the get_random package, I can call the get_random > > program > > > from the command line in the virtualenv and get the expected > results. > > In > > > otherwords, if I run the following in a terminal I get a resulting > > random > > > number, like so: > > > > > > sgambino-m1:~/vnv_for_pip > get_random > > > 0.0259274305036 > > > > > > However, if I try to import the get_random package into a python > REPL > > I > > do > > > not see > > > a complete list of what is in the package. I only see the following: > > > > > > >>> dir(get_random) > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > > > '__path__'] > > > > > > but I was expecting to see: > > > > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > If I try to import the get_random package into a script and run the > > script, > > > I get the following error: > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > Traceback (most recent call last): > > > File "./try_get_random.py", line 5, in > > > get_random.print_random() > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > Here is some more detail from the REPL that may give a clue. I'm > > wondering > > > if there is something in the setup.py that I haven't > > > defined correctly or not defined at all. I could share that if > someone > > > thinks it is worth a look. The setup.py that I started with > > > was the one that is provided from > > https://github.com/pypa/sampleproject > > > > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > > Type "help", "copyright", "credits" or "license" for more > information. > > > >>> import get_random > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > '__path__'] > > > >>> print(get_random.__file__) > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > >>> print(get_random.__package__) > > > None > > > >>> print(get_random.__path__) > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > > > > If you have bothered to read this far, I hope this has made some > sense > > and > > > I thank you for any ideas you may be willing to share! > > > Steve Gambino > > > -- > > > Best, > > > Steve > > > Hello friends, > > > I'm attempting to learn how to create a pip installable package. So > > far > > > the attempt has been relatively successful but for one nagging > issue. > > I'm > > > hoping if I describe the issue here clearly enough that someone can > > offer > > > pointers to help me get to a resolution. > > > I've created the package (named get_random) successfully with > > setuptools > > > and have been able to do a pip install of it in a virtualenv. > > > The package "get_random" contains a trivial program also named > > > "get_random". The program, "get_random", imports one module, > 'random', > > and > > > it has the functions, main(), get_random() and print_random(). After > > the > > > pip install of the get_random package, I can call the get_random > > program > > > from the command line in the virtualenv and get the expected > results. > > In > > > otherwords, if I run the following in a terminal I get a resulting > > random > > > number, like so: > > > sgambino-m1:~/vnv_for_pip > get_random > > > 0.0259274305036 > > > However, if I try to import the get_random package into a python > REPL > > I > > do > > > not see > > > a complete list of what is in the package. I only see the following: > > > >>> dir(get_random) > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > > > '__package__', > > > '__path__'] > > > > > > but I was expecting to see: > > > > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > If I try to import the get_random package into a script and run the > > > script, I get the following error: > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > Traceback (most recent call last): > > > ** File "./try_get_random.py", line 5, in > > > ****** get_random.print_random() > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > Here is some more detail from the REPL that may give a clue.** I'm > > > wondering if there is something in the setup.py that I haven't > > > defined correctly or not defined at all. I could share that if > someone > > > thinks it is worth a look. The setup.py that I started with > > > was the one that is provided from > > [1]https://github.com/pypa/sampleproject > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > > > Type "help", "copyright", "credits" or "license" for more > information. > > > >>> import get_random > > > >>> dir(get_random) > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > '__path__'] > > > >>> print(get_random.__file__) > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > >>> print(get_random.__package__) > > > None > > > >>> print(get_random.__path__) > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > If you have bothered to read this far, I hope this has made some > sense > > and > > > I thank you for any ideas you may be willing to share! > > > Steve Gambino > > > -- > > > Best,** > > > Steve > > > > > > References > > > > > > Visible links > > > 1. https://github.com/pypa/sampleproject > > > > > _______________________________________________ > > TriZPUG mailing list > > TriZPUG at python.org > > https://mail.python.org/mailman/listinfo/trizpug > > http://tripython.org is the Triangle Python Users Group > > > -- > Best, > Steve > Hi David, > Thank you for your questions.** My answers are inline below.** I've made > the code available here so that you can look at the setup.py > See [1]https://github.com/sgambino/project-random > I was a little confused reading your description, mainly because I wasn't > ** **sure when you said "package" whether you meant a distributable unit > of > ** **Python code with a setup.py file, or whether you meant "an importable > ** **directory on sys.path containing an __init__.py file". > > I see what you mean how my use of terms was confusing. I should have > said a > > distributable unit of Python code with a setup.py file > > ** **Is there an importable package directory named "get_random" > containing an > ** **__init__.py file? Or is there instead a get_random.py module? > > > Yes, there was an importable package directory named "get_random".** > Note that > > since the original post, I renamed the distributable unit to > "sample_random" and > > the importable package directory to "try_random" > ** **If you have an importable package directory named get_random, then > the > ** **behavior you saw is expected. When you import a package, the only > names > ** **you see in that package are the ones defined (or imported into) the > ** **__init__.py file itself. To see anything in any other module inside > that > ** **package you have to import that explicity, in your main program file > or in > ** **the __init__.py file. > > ** **Which form does your get_random program take? There are at least two > ways > ** **to distribute Python scripts, one that uses setuptools and console > entry > ** **points, and one doesn't. > > > The form of the program uses setuptools and console entry points. This > is > > the topic where I think my understanding is the weakest and need help > with > ** **Yes, if you shared your full setup.py file with us, that would > probably > ** **answer those questions and more, and would be helpful in diagnosing > your > ** **problem. If you would share the full layout of your distributable > package > ** **files, that would help too. > > Yes, of course. See [2]https://github.com/sgambino/project-random > > And note that as mentioned earlier, I renamed the distributable unit > from > >** to "sample_random" and the python package to "try_random" > > > > I reported earlier that after doing a pip install, I could run the > program from > > command line but if I tried to import the package into a script or into > the > > python REPL itself that I could not see the complete list of the package > > so as to be able call its functions.**** It appears my issue was with > the > > way I was importing it into the namespace.** I was declaring "import > sample_random" > > However, in the IRC channel, James (jwhisnant) was helping me, and he > declared the > > import in this form: "from sample_random import try_random"****** This > appears > > to have resolved the issue.** I would like to better understand why so > that > > I do not repeat this behavior in the future.** I suspect it may be with > the > > way I declared the "entry_points" in the setup.py**** I think need a > better understanding > > of entry points in general and also a clearer understanding of the > semantic elements of the > > form of how they are specified in the setup.py**** I used the example > setup.py as referenced > > in the tutorials at [3]https://packaging.python.org/**** There seems to > be ample documentation > > and commentary in the setup.py concerning entry points but it is still > taking awhile for > > it to become clear enough in my understanding so that I can confidently > say, I truly > > understand. :-) > > > > Thanks, > > Steve Gambino > On Wed, Nov 1, 2017 at 10:17 PM David Handy <[4]david at handysoftware.com> > wrote: > > ** **Hi Steve - > > ** **I was a little confused reading your description, mainly because I > wasn't > ** **sure when you said "package" whether you meant a distributable unit > of > ** **Python code with a setup.py file, or whether you meant "an > importable > ** **directory on sys.path containing an __init__.py file". > > ** **Is there an importable package directory named "get_random" > containing an > ** **__init__.py file? Or is there instead a get_random.py module? > > ** **If you have an importable package directory named get_random, then > the > ** **behavior you saw is expected. When you import a package, the only > names > ** **you see in that package are the ones defined (or imported into) the > ** **__init__.py file itself. To see anything in any other module inside > that > ** **package you have to import that explicity, in your main program > file or in > ** **the __init__.py file. > > ** **Which form does your get_random program take? There are at least > two ways > ** **to distribute Python scripts, one that uses setuptools and console > entry > ** **points, and one doesn't. > > ** **Yes, if you shared your full setup.py file with us, that would > probably > ** **answer those questions and more, and would be helpful in diagnosing > your > ** **problem. If you would share the full layout of your distributable > package > ** **files, that would help too. > > ** **Thanks, > > ** **David H > > ** **On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > ** **<[5]stevegambino at gmail.com> said: > > ** **> _______________________________________________ > ** **> TriZPUG mailing list > ** **> [6]TriZPUG at python.org > ** **> [7]https://mail.python.org/mailman/listinfo/trizpug > ** **> [8]http://tripython.org is the Triangle Python Users Group > ** **> Hello friends, > ** **> > ** **> I'm attempting to learn how to create a pip installable package. > So far > ** **the > ** **> attempt has been relatively successful but for one nagging issue. > I'm > ** **> hoping if I describe the issue here clearly enough that someone > can > ** **offer > ** **> pointers to help me get to a resolution. > ** **> > ** **> I've created the package (named get_random) successfully with > setuptools > ** **> and have been able to do a pip install of it in a virtualenv. > ** **> > ** **> The package "get_random" contains a trivial program also named > ** **> "get_random". The program, "get_random", imports one module, > 'random', > ** **and > ** **> it has the functions, main(), get_random() and print_random(). > After the > ** **> pip install of the get_random package, I can call the get_random > program > ** **> from the command line in the virtualenv and get the expected > results. In > ** **> otherwords, if I run the following in a terminal I get a > resulting > ** **random > ** **> number, like so: > ** **> > ** **> sgambino-m1:~/vnv_for_pip > get_random > ** **> 0.0259274305036 > ** **> > ** **> However, if I try to import the get_random package into a python > REPL I > ** **do > ** **> not see > ** **> a complete list of what is in the package. I only see the > following: > ** **> > ** **> >>> dir(get_random) > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> > ** **> but I was expecting to see: > ** **> > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> 'get_random', 'main', 'print_random', 'random'] > ** **> > ** **> If I try to import the get_random package into a script and run > the > ** **script, > ** **> I get the following error: > ** **> > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > ** **> Traceback (most recent call last): > ** **> File "./try_get_random.py", line 5, in > ** **> get_random.print_random() > ** **> AttributeError: 'module' object has no attribute 'print_random' > ** **> > ** **> Here is some more detail from the REPL that may give a clue. I'm > ** **wondering > ** **> if there is something in the setup.py that I haven't > ** **> defined correctly or not defined at all. I could share that if > someone > ** **> thinks it is worth a look. The setup.py that I started with > ** **> was the one that is provided from > [9]https://github.com/pypa/sampleproject > ** **> > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > ** **> Type "help", "copyright", "credits" or "license" for more > information. > ** **> >>> import get_random > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> >>> print(get_random.__file__) > ** **> > ** > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > ** **> >>> print(get_random.__package__) > ** **> None > ** **> >>> print(get_random.__path__) > ** **> > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > ** **> > ** **> If you have bothered to read this far, I hope this has made some > sense > ** **and > ** **> I thank you for any ideas you may be willing to share! > ** **> Steve Gambino > ** **> -- > ** **> Best, > ** **> Steve > ** **> Hello friends, > ** **> I'm attempting to learn how to create a pip installable package. > So far > ** **> the attempt has been relatively successful but for one nagging > issue. > ** **I'm > ** **> hoping if I describe the issue here clearly enough that someone > can > ** **offer > ** **> pointers to help me get to a resolution. > ** **> I've created the package (named get_random) successfully with > setuptools > ** **> and have been able to do a pip install of it in a virtualenv. > ** **> The package "get_random" contains a trivial program also named > ** **> "get_random". The program, "get_random", imports one module, > 'random', > ** **and > ** **> it has the functions, main(), get_random() and print_random(). > After the > ** **> pip install of the get_random package, I can call the get_random > program > ** **> from the command line in the virtualenv and get the expected > results. In > ** **> otherwords, if I run the following in a terminal I get a > resulting > ** **random > ** **> number, like so: > ** **> sgambino-m1:~/vnv_for_pip > get_random > ** **> 0.0259274305036 > ** **> However, if I try to import the get_random package into a python > REPL I > ** **do > ** **> not see > ** **> a complete list of what is in the package. I only see the > following: > ** **> >>> dir(get_random) > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > ** **> '__package__', > ** **> '__path__'] > ** **> > ** **> but I was expecting to see: > ** **> > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> 'get_random', 'main', 'print_random', 'random'] > ** **> > ** **> If I try to import the get_random package into a script and run > the > ** **> script, I get the following error: > ** **> > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > ** **> Traceback (most recent call last): > ** **> ** File "./try_get_random.py", line 5, in > ** **> ****** get_random.print_random() > ** **> AttributeError: 'module' object has no attribute 'print_random' > ** **> > ** **> Here is some more detail from the REPL that may give a clue.** > I'm > ** **> wondering if there is something in the setup.py that I haven't > ** **> defined correctly or not defined at all. I could share that if > someone > ** **> thinks it is worth a look. The setup.py that I started with > ** **> was the one that is provided from > ** **[1][10]https://github.com/pypa/sampleproject > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > ** **> Type "help", "copyright", "credits" or "license" for more > information. > ** **> >>> import get_random > ** **> >>> dir(get_random) > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > '__package__', > ** **> '__path__'] > ** **> >>> print(get_random.__file__) > ** **> > ** > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > ** **> >>> print(get_random.__package__) > ** **> None > ** **> >>> print(get_random.__path__) > ** **> > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > ** **> If you have bothered to read this far, I hope this has made some > sense > ** **and > ** **> I thank you for any ideas you may be willing to share! > ** **> Steve Gambino > ** **> -- > ** **> Best,** > ** **> Steve > ** **> > ** **> References > ** **> > ** **> Visible links > ** **> 1. [11]https://github.com/pypa/sampleproject > ** **> > _______________________________________________ > TriZPUG mailing list > [12]TriZPUG at python.org > [13]https://mail.python.org/mailman/listinfo/trizpug > [14]http://tripython.org is the Triangle Python Users Group > > -- > Best,** > Steve > > References > > Visible links > 1. https://github.com/sgambino/project-random > 2. https://github.com/sgambino/project-random > 3. https://packaging.python.org/ > 4. mailto:david at handysoftware.com > 5. mailto:stevegambino at gmail.com > 6. mailto:TriZPUG at python.org > 7. https://mail.python.org/mailman/listinfo/trizpug > 8. http://tripython.org/ > 9. https://github.com/pypa/sampleproject > 10. https://github.com/pypa/sampleproject > 11. https://github.com/pypa/sampleproject > 12. mailto:TriZPUG at python.org > 13. https://mail.python.org/mailman/listinfo/trizpug > 14. http://tripython.org/ > References Visible links 1. https://github.com/sgambino/project-random.git From stevegambino at gmail.com Thu Nov 2 13:13:20 2017 From: stevegambino at gmail.com (Steve Gambino) Date: Thu, 02 Nov 2017 17:13:20 +0000 Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: <1509633608.63253104@apps.rackspace.com> References: <1509588459.712518936@apps.rackspace.com> <1509633608.63253104@apps.rackspace.com> Message-ID: Hi Dave, Thank you so much for taking the time to elaborate on each step of the setup.py process that I had asked about. It makes so much more sense now. I'll be able to take this knowledge and apply it to one of our internal tools which we are currently working on. Yes, very helpful indeed! Steve On Thu, Nov 2, 2017 at 10:47 AM David Handy wrote: > Hi Steve - > > > > Actually people refer to a "distributable unit of Python code" as a > "package" all the time, it was only confusing to me in this context > because we were switching back and forth talking about both kinds of > packages. :) > > > > Here's what I did: > > > > git clone [1]https://github.com/sgambino/project-random.git > > virtualenv -p python3 env > > source env/bin/activate > > pip install -e project-random/ > > sample_random > > > > Which printed a random number: > > 0.5678855151148471 > > > > So far so good! Now for importing it: > > > > python > > # This just imports the __init__.py file in the sample_random directory > > >>> import sample_random > > # This imports the try_random module from the sample_random directory > > >>> from sample_random import try_random > > # This of course calls the main() function in the try_random module > > >>> try_random.main() > 0.20974369539964732 > > > > This is all standard behavior for Python "packages" (importable > directories) whether or not pip/virtualenv is involved. > > > > As for entry points - notice in your setup.py file, you have this > parameter in your call to setup(): > > > > entry_points={ > > 'console_scripts': [ > > 'sample_random=sample_random.try_random:main', > > ], > > } > > > > What this means is: Tell setuptools to create a list of scripts > (currently > a list of just one). Create a script named "sample_random" that imports > the try_random module from the sample_random package and calls the > main() > function to run it. > > > > If you look in the bin directory of the virtual environment where pip > install this "package" (distribution of code), you see that setuptools > created a file named sample_random with these contents: > > > > #!/home/david/temp/env/bin/python3 > # EASY-INSTALL-ENTRY-SCRIPT: > 'sample-random','console_scripts','sample_random' > __requires__ = 'sample-random' > import re > import sys > from pkg_resources import load_entry_point > > if __name__ == '__main__': > sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) > sys.exit( > load_entry_point('sample-random', 'console_scripts', > 'sample_random')() > ) > > > > Notice at the top of the file is a #! line that points to the python > interpreter for this virtual environment. The rest of the gobbledygook > loads your loads your try_random module and runs that main function in > such a way that it looks like it got run from the command line. It uses > metadata installed by setuptools in the site-packages of your virtual > environment to find the entry point, and to know which package and > module > to load and which function to run. > > > > I hope this helps. I gotta get back to work now! > > David H > > > > > > On Thursday, November 2, 2017 1:07am, "Steve Gambino" > said: > > > _______________________________________________ > > TriZPUG mailing list > > TriZPUG at python.org > > https://mail.python.org/mailman/listinfo/trizpug > > http://tripython.org is the Triangle Python Users Group > > Hi David, > > Thank you for your questions. My answers are inline below. I've made > > the code available here so that you can look at the setup.py > > See https://github.com/sgambino/project-random > > > > I was a little confused reading your description, mainly because I > wasn't > > sure when you said "package" whether you meant a distributable unit of > > Python code with a setup.py file, or whether you meant "an importable > > directory on sys.path containing an __init__.py file". > > > > > > > I see what you mean how my use of terms was confusing. I should have > said > > a > > > distributable unit of Python code with a setup.py file > > > > > > > > Is there an importable package directory named "get_random" containing > an > > __init__.py file? Or is there instead a get_random.py module? > > > > > Yes, there was an importable package directory named "get_random". > Note > > that > > > since the original post, I renamed the distributable unit to > > "sample_random" and > > > the importable package directory to "try_random" > > > > If you have an importable package directory named get_random, then the > > behavior you saw is expected. When you import a package, the only > names > > you see in that package are the ones defined (or imported into) the > > __init__.py file itself. To see anything in any other module inside > that > > package you have to import that explicity, in your main program file > or > > in > > the __init__.py file. > > > > > > > > Which form does your get_random program take? There are at least two > ways > > to distribute Python scripts, one that uses setuptools and console > entry > > points, and one doesn't. > > > > > The form of the program uses setuptools and console entry points. > This > is > > > the topic where I think my understanding is the weakest and need > help > with > > > > Yes, if you shared your full setup.py file with us, that would > probably > > answer those questions and more, and would be helpful in diagnosing > your > > problem. If you would share the full layout of your distributable > package > > files, that would help too. > > > > > Yes, of course. See https://github.com/sgambino/project-random > > > And note that as mentioned earlier, I renamed the distributable unit > from > > > to "sample_random" and the python package to "try_random" > > > > > > I reported earlier that after doing a pip install, I could run the > > program from > > > command line but if I tried to import the package into a script or > into > > the > > > python REPL itself that I could not see the complete list of the > package > > > so as to be able call its functions. It appears my issue was with > the > > > way I was importing it into the namespace. I was declaring "import > > sample_random" > > > However, in the IRC channel, James (jwhisnant) was helping me, and > he > > declared the > > > import in this form: "from sample_random import try_random" This > > appears > > > to have resolved the issue. I would like to better understand why so > that > > > I do not repeat this behavior in the future. I suspect it may be > with > the > > > way I declared the "entry_points" in the setup.py I think need a > better > > understanding > > > of entry points in general and also a clearer understanding of the > > semantic elements of the > > > form of how they are specified in the setup.py I used the example > > setup.py as referenced > > > in the tutorials at https://packaging.python.org/ There seems to be > > ample documentation > > > and commentary in the setup.py concerning entry points but it is > still > > taking awhile for > > > it to become clear enough in my understanding so that I can > confidently > > say, I truly > > > understand. :-) > > > > > > Thanks, > > > Steve Gambino > > > > On Wed, Nov 1, 2017 at 10:17 PM David Handy > > wrote: > > > > > Hi Steve - > > > > > > > > > > > > I was a little confused reading your description, mainly because I > > > wasn't > > > sure when you said "package" whether you meant a distributable unit > of > > > Python code with a setup.py file, or whether you meant "an > importable > > > directory on sys.path containing an __init__.py file". > > > > > > > > > > > > Is there an importable package directory named "get_random" > containing > > > an > > > __init__.py file? Or is there instead a get_random.py module? > > > > > > > > > > > > If you have an importable package directory named get_random, then > the > > > behavior you saw is expected. When you import a package, the only > names > > > you see in that package are the ones defined (or imported into) the > > > __init__.py file itself. To see anything in any other module inside > that > > > package you have to import that explicity, in your main program file > or > > > in > > > the __init__.py file. > > > > > > > > > > > > Which form does your get_random program take? There are at least two > > > ways > > > to distribute Python scripts, one that uses setuptools and console > entry > > > points, and one doesn't. > > > > > > > > > > > > Yes, if you shared your full setup.py file with us, that would > probably > > > answer those questions and more, and would be helpful in diagnosing > your > > > problem. If you would share the full layout of your distributable > > > package > > > files, that would help too. > > > > > > > > > > > > Thanks, > > > > > > David H > > > > > > > > > > > > > > > > > > On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > > > said: > > > > > > > _______________________________________________ > > > > TriZPUG mailing list > > > > TriZPUG at python.org > > > > https://mail.python.org/mailman/listinfo/trizpug > > > > http://tripython.org is the Triangle Python Users Group > > > > Hello friends, > > > > > > > > I'm attempting to learn how to create a pip installable package. > So > > > far > > > the > > > > attempt has been relatively successful but for one nagging issue. > > I'm > > > > hoping if I describe the issue here clearly enough that someone > can > > > offer > > > > pointers to help me get to a resolution. > > > > > > > > I've created the package (named get_random) successfully with > > > setuptools > > > > and have been able to do a pip install of it in a virtualenv. > > > > > > > > The package "get_random" contains a trivial program also named > > > > "get_random". The program, "get_random", imports one module, > > 'random', > > > and > > > > it has the functions, main(), get_random() and print_random(). > After > > > the > > > > pip install of the get_random package, I can call the get_random > > > program > > > > from the command line in the virtualenv and get the expected > > results. > > > In > > > > otherwords, if I run the following in a terminal I get a resulting > > > random > > > > number, like so: > > > > > > > > sgambino-m1:~/vnv_for_pip > get_random > > > > 0.0259274305036 > > > > > > > > However, if I try to import the get_random package into a python > > REPL > > > I > > > do > > > > not see > > > > a complete list of what is in the package. I only see the > following: > > > > > > > > >>> dir(get_random) > > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > > > '__path__'] > > > > > > > > but I was expecting to see: > > > > > > > > >>> dir(get_random) > > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > > > If I try to import the get_random package into a script and run > the > > > script, > > > > I get the following error: > > > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > > Traceback (most recent call last): > > > > File "./try_get_random.py", line 5, in > > > > get_random.print_random() > > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > > > Here is some more detail from the REPL that may give a clue. I'm > > > wondering > > > > if there is something in the setup.py that I haven't > > > > defined correctly or not defined at all. I could share that if > > someone > > > > thinks it is worth a look. The setup.py that I started with > > > > was the one that is provided from > > > https://github.com/pypa/sampleproject > > > > > > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > > > > Type "help", "copyright", "credits" or "license" for more > > information. > > > > >>> import get_random > > > > >>> dir(get_random) > > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > > '__path__'] > > > > >>> print(get_random.__file__) > > > > > > > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > > >>> print(get_random.__package__) > > > > None > > > > >>> print(get_random.__path__) > > > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > > > > > > If you have bothered to read this far, I hope this has made some > > sense > > > and > > > > I thank you for any ideas you may be willing to share! > > > > Steve Gambino > > > > -- > > > > Best, > > > > Steve > > > > Hello friends, > > > > I'm attempting to learn how to create a pip installable package. > So > > > far > > > > the attempt has been relatively successful but for one nagging > > issue. > > > I'm > > > > hoping if I describe the issue here clearly enough that someone > can > > > offer > > > > pointers to help me get to a resolution. > > > > I've created the package (named get_random) successfully with > > > setuptools > > > > and have been able to do a pip install of it in a virtualenv. > > > > The package "get_random" contains a trivial program also named > > > > "get_random". The program, "get_random", imports one module, > > 'random', > > > and > > > > it has the functions, main(), get_random() and print_random(). > After > > > the > > > > pip install of the get_random package, I can call the get_random > > > program > > > > from the command line in the virtualenv and get the expected > > results. > > > In > > > > otherwords, if I run the following in a terminal I get a resulting > > > random > > > > number, like so: > > > > sgambino-m1:~/vnv_for_pip > get_random > > > > 0.0259274305036 > > > > However, if I try to import the get_random package into a python > > REPL > > > I > > > do > > > > not see > > > > a complete list of what is in the package. I only see the > following: > > > > >>> dir(get_random) > > > > >>> ['__builtins__', '__doc__', '__file__', '__name__', > > > > '__package__', > > > > '__path__'] > > > > > > > > but I was expecting to see: > > > > > > > > >>> dir(get_random) > > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > > 'get_random', 'main', 'print_random', 'random'] > > > > > > > > If I try to import the get_random package into a script and run > the > > > > script, I get the following error: > > > > > > > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > > > Traceback (most recent call last): > > > > ** File "./try_get_random.py", line 5, in > > > > ****** get_random.print_random() > > > > AttributeError: 'module' object has no attribute 'print_random' > > > > > > > > Here is some more detail from the REPL that may give a clue.** I'm > > > > wondering if there is something in the setup.py that I haven't > > > > defined correctly or not defined at all. I could share that if > > someone > > > > thinks it is worth a look. The setup.py that I started with > > > > was the one that is provided from > > > [1]https://github.com/pypa/sampleproject > > > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > darwin > > > > Type "help", "copyright", "credits" or "license" for more > > information. > > > > >>> import get_random > > > > >>> dir(get_random) > > > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > > > > '__path__'] > > > > >>> print(get_random.__file__) > > > > > > > > > > > > > > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > > > >>> print(get_random.__package__) > > > > None > > > > >>> print(get_random.__path__) > > > > > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > > > If you have bothered to read this far, I hope this has made some > > sense > > > and > > > > I thank you for any ideas you may be willing to share! > > > > Steve Gambino > > > > -- > > > > Best,** > > > > Steve > > > > > > > > References > > > > > > > > Visible links > > > > 1. https://github.com/pypa/sampleproject > > > > > > > _______________________________________________ > > > TriZPUG mailing list > > > TriZPUG at python.org > > > https://mail.python.org/mailman/listinfo/trizpug > > > http://tripython.org is the Triangle Python Users Group > > > > > -- > > Best, > > Steve > > Hi David, > > Thank you for your questions.** My answers are inline below.** I've > made > > the code available here so that you can look at the setup.py > > See [1]https://github.com/sgambino/project-random > > I was a little confused reading your description, mainly because I > wasn't > > ** **sure when you said "package" whether you meant a distributable > unit > > of > > ** **Python code with a setup.py file, or whether you meant "an > importable > > ** **directory on sys.path containing an __init__.py file". > > > I see what you mean how my use of terms was confusing. I should have > > said a > > > distributable unit of Python code with a setup.py file > > > > ** **Is there an importable package directory named "get_random" > > containing an > > ** **__init__.py file? Or is there instead a get_random.py module? > > > > > Yes, there was an importable package directory named "get_random".** > > Note that > > > since the original post, I renamed the distributable unit to > > "sample_random" and > > > the importable package directory to "try_random" > > ** **If you have an importable package directory named get_random, > then > > the > > ** **behavior you saw is expected. When you import a package, the only > > names > > ** **you see in that package are the ones defined (or imported into) > the > > ** **__init__.py file itself. To see anything in any other module > inside > > that > > ** **package you have to import that explicity, in your main program > file > > or in > > ** **the __init__.py file. > > > > ** **Which form does your get_random program take? There are at least > two > > ways > > ** **to distribute Python scripts, one that uses setuptools and > console > > entry > > ** **points, and one doesn't. > > > > > The form of the program uses setuptools and console entry points. > This > > is > > > the topic where I think my understanding is the weakest and need > help > > with > > ** **Yes, if you shared your full setup.py file with us, that would > > probably > > ** **answer those questions and more, and would be helpful in > diagnosing > > your > > ** **problem. If you would share the full layout of your distributable > > package > > ** **files, that would help too. > > > Yes, of course. See [2]https://github.com/sgambino/project-random > > > And note that as mentioned earlier, I renamed the distributable unit > > from > > >** to "sample_random" and the python package to "try_random" > > > > > > I reported earlier that after doing a pip install, I could run the > > program from > > > command line but if I tried to import the package into a script or > into > > the > > > python REPL itself that I could not see the complete list of the > package > > > so as to be able call its functions.**** It appears my issue was > with > > the > > > way I was importing it into the namespace.** I was declaring "import > > sample_random" > > > However, in the IRC channel, James (jwhisnant) was helping me, and > he > > declared the > > > import in this form: "from sample_random import try_random"****** > This > > appears > > > to have resolved the issue.** I would like to better understand why > so > > that > > > I do not repeat this behavior in the future.** I suspect it may be > with > > the > > > way I declared the "entry_points" in the setup.py**** I think need a > > better understanding > > > of entry points in general and also a clearer understanding of the > > semantic elements of the > > > form of how they are specified in the setup.py**** I used the > example > > setup.py as referenced > > > in the tutorials at [3]https://packaging.python.org/**** There > seems > to > > be ample documentation > > > and commentary in the setup.py concerning entry points but it is > still > > taking awhile for > > > it to become clear enough in my understanding so that I can > confidently > > say, I truly > > > understand. :-) > > > > > > Thanks, > > > Steve Gambino > > On Wed, Nov 1, 2017 at 10:17 PM David Handy <[4] > david at handysoftware.com> > > wrote: > > > > ** **Hi Steve - > > > > ** **I was a little confused reading your description, mainly because > I > > wasn't > > ** **sure when you said "package" whether you meant a distributable > unit > > of > > ** **Python code with a setup.py file, or whether you meant "an > > importable > > ** **directory on sys.path containing an __init__.py file". > > > > ** **Is there an importable package directory named "get_random" > > containing an > > ** **__init__.py file? Or is there instead a get_random.py module? > > > > ** **If you have an importable package directory named get_random, > then > > the > > ** **behavior you saw is expected. When you import a package, the only > > names > > ** **you see in that package are the ones defined (or imported into) > the > > ** **__init__.py file itself. To see anything in any other module > inside > > that > > ** **package you have to import that explicity, in your main program > > file or in > > ** **the __init__.py file. > > > > ** **Which form does your get_random program take? There are at least > > two ways > > ** **to distribute Python scripts, one that uses setuptools and > console > > entry > > ** **points, and one doesn't. > > > > ** **Yes, if you shared your full setup.py file with us, that would > > probably > > ** **answer those questions and more, and would be helpful in > diagnosing > > your > > ** **problem. If you would share the full layout of your distributable > > package > > ** **files, that would help too. > > > > ** **Thanks, > > > > ** **David H > > > > ** **On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" > > ** **<[5]stevegambino at gmail.com> said: > > > > ** **> _______________________________________________ > > ** **> TriZPUG mailing list > > ** **> [6]TriZPUG at python.org > > ** **> [7]https://mail.python.org/mailman/listinfo/trizpug > > ** **> [8]http://tripython.org is the Triangle Python Users Group > > ** **> Hello friends, > > ** **> > > ** **> I'm attempting to learn how to create a pip installable > package. > > So far > > ** **the > > ** **> attempt has been relatively successful but for one nagging > issue. > > I'm > > ** **> hoping if I describe the issue here clearly enough that someone > > can > > ** **offer > > ** **> pointers to help me get to a resolution. > > ** **> > > ** **> I've created the package (named get_random) successfully with > > setuptools > > ** **> and have been able to do a pip install of it in a virtualenv. > > ** **> > > ** **> The package "get_random" contains a trivial program also named > > ** **> "get_random". The program, "get_random", imports one module, > > 'random', > > ** **and > > ** **> it has the functions, main(), get_random() and print_random(). > > After the > > ** **> pip install of the get_random package, I can call the > get_random > > program > > ** **> from the command line in the virtualenv and get the expected > > results. In > > ** **> otherwords, if I run the following in a terminal I get a > > resulting > > ** **random > > ** **> number, like so: > > ** **> > > ** **> sgambino-m1:~/vnv_for_pip > get_random > > ** **> 0.0259274305036 > > ** **> > > ** **> However, if I try to import the get_random package into a > python > > REPL I > > ** **do > > ** **> not see > > ** **> a complete list of what is in the package. I only see the > > following: > > ** **> > > ** **> >>> dir(get_random) > > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > ** **> '__path__'] > > ** **> > > ** **> but I was expecting to see: > > ** **> > > ** **> >>> dir(get_random) > > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > ** **> 'get_random', 'main', 'print_random', 'random'] > > ** **> > > ** **> If I try to import the get_random package into a script and run > > the > > ** **script, > > ** **> I get the following error: > > ** **> > > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > ** **> Traceback (most recent call last): > > ** **> File "./try_get_random.py", line 5, in > > ** **> get_random.print_random() > > ** **> AttributeError: 'module' object has no attribute 'print_random' > > ** **> > > ** **> Here is some more detail from the REPL that may give a clue. > I'm > > ** **wondering > > ** **> if there is something in the setup.py that I haven't > > ** **> defined correctly or not defined at all. I could share that if > > someone > > ** **> thinks it is worth a look. The setup.py that I started with > > ** **> was the one that is provided from > > [9]https://github.com/pypa/sampleproject > > ** **> > > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > > darwin > > ** **> Type "help", "copyright", "credits" or "license" for more > > information. > > ** **> >>> import get_random > > ** **> >>> dir(get_random) > > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > ** **> '__path__'] > > ** **> >>> print(get_random.__file__) > > ** **> > > ** > > > > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > ** **> >>> print(get_random.__package__) > > ** **> None > > ** **> >>> print(get_random.__path__) > > ** **> > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > ** **> > > ** **> If you have bothered to read this far, I hope this has made > some > > sense > > ** **and > > ** **> I thank you for any ideas you may be willing to share! > > ** **> Steve Gambino > > ** **> -- > > ** **> Best, > > ** **> Steve > > ** **> Hello friends, > > ** **> I'm attempting to learn how to create a pip installable > package. > > So far > > ** **> the attempt has been relatively successful but for one nagging > > issue. > > ** **I'm > > ** **> hoping if I describe the issue here clearly enough that someone > > can > > ** **offer > > ** **> pointers to help me get to a resolution. > > ** **> I've created the package (named get_random) successfully with > > setuptools > > ** **> and have been able to do a pip install of it in a virtualenv. > > ** **> The package "get_random" contains a trivial program also named > > ** **> "get_random". The program, "get_random", imports one module, > > 'random', > > ** **and > > ** **> it has the functions, main(), get_random() and print_random(). > > After the > > ** **> pip install of the get_random package, I can call the > get_random > > program > > ** **> from the command line in the virtualenv and get the expected > > results. In > > ** **> otherwords, if I run the following in a terminal I get a > > resulting > > ** **random > > ** **> number, like so: > > ** **> sgambino-m1:~/vnv_for_pip > get_random > > ** **> 0.0259274305036 > > ** **> However, if I try to import the get_random package into a > python > > REPL I > > ** **do > > ** **> not see > > ** **> a complete list of what is in the package. I only see the > > following: > > ** **> >>> dir(get_random) > > ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', > > ** **> '__package__', > > ** **> '__path__'] > > ** **> > > ** **> but I was expecting to see: > > ** **> > > ** **> >>> dir(get_random) > > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > ** **> 'get_random', 'main', 'print_random', 'random'] > > ** **> > > ** **> If I try to import the get_random package into a script and run > > the > > ** **> script, I get the following error: > > ** **> > > ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > > ** **> Traceback (most recent call last): > > ** **> ** File "./try_get_random.py", line 5, in > > ** **> ****** get_random.print_random() > > ** **> AttributeError: 'module' object has no attribute 'print_random' > > ** **> > > ** **> Here is some more detail from the REPL that may give a clue.** > > I'm > > ** **> wondering if there is something in the setup.py that I haven't > > ** **> defined correctly or not defined at all. I could share that if > > someone > > ** **> thinks it is worth a look. The setup.py that I started with > > ** **> was the one that is provided from > > ** **[1][10]https://github.com/pypa/sampleproject > > ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) > > ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on > > darwin > > ** **> Type "help", "copyright", "credits" or "license" for more > > information. > > ** **> >>> import get_random > > ** **> >>> dir(get_random) > > ** **> ['__builtins__', '__doc__', '__file__', '__name__', > > '__package__', > > ** **> '__path__'] > > ** **> >>> print(get_random.__file__) > > ** **> > > ** > > > > **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc > > ** **> >>> print(get_random.__package__) > > ** **> None > > ** **> >>> print(get_random.__path__) > > ** **> > > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > > ** **> If you have bothered to read this far, I hope this has made > some > > sense > > ** **and > > ** **> I thank you for any ideas you may be willing to share! > > ** **> Steve Gambino > > ** **> -- > > ** **> Best,** > > ** **> Steve > > ** **> > > ** **> References > > ** **> > > ** **> Visible links > > ** **> 1. [11]https://github.com/pypa/sampleproject > > ** **> > > _______________________________________________ > > TriZPUG mailing list > > [12]TriZPUG at python.org > > [13]https://mail.python.org/mailman/listinfo/trizpug > > [14]http://tripython.org is the Triangle Python Users Group > > > > -- > > Best,** > > Steve > > > > References > > > > Visible links > > 1. https://github.com/sgambino/project-random > > 2. https://github.com/sgambino/project-random > > 3. https://packaging.python.org/ > > 4. mailto:david at handysoftware.com > > 5. mailto:stevegambino at gmail.com > > 6. mailto:TriZPUG at python.org > > 7. https://mail.python.org/mailman/listinfo/trizpug > > 8. http://tripython.org/ > > 9. https://github.com/pypa/sampleproject > > 10. https://github.com/pypa/sampleproject > > 11. https://github.com/pypa/sampleproject > > 12. mailto:TriZPUG at python.org > > 13. https://mail.python.org/mailman/listinfo/trizpug > > 14. http://tripython.org/ > > > > References > > Visible links > 1. https://github.com/sgambino/project-random.git > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > -- Best, Steve -------------- next part -------------- Hi Dave, Thank you so much for taking the time to elaborate on each step of the setup.py process that I had asked about. It makes so much more sense now. I'll be able to take this knowledge and apply it to one of our internal tools which we are currently working on.** Yes, very helpful indeed! Steve On Thu, Nov 2, 2017 at 10:47 AM David Handy <[1]david at handysoftware.com> wrote: ** **Hi Steve - ** **Actually people refer to a "distributable unit of Python code" as a ** **"package" all the time, it was only confusing to me in this context ** **because we were switching back and forth talking about both kinds of ** **packages. :) ** **Here's what I did: ** **git clone [1][2]https://github.com/sgambino/project-random.git ** **virtualenv -p python3 env ** **source env/bin/activate ** **pip install -e project-random/ ** **sample_random ** **Which printed a random number: ** **0.5678855151148471 ** **So far so good! Now for importing it: ** **python ** **# This just imports the __init__.py file in the sample_random directory ** **>>> import sample_random ** **# This imports the try_random module from the sample_random directory ** **>>> from sample_random import try_random ** **# This of course calls the main() function in the try_random module ** **>>> try_random.main() ** **0.20974369539964732 ** **This is all standard behavior for Python "packages" (importable ** **directories) whether or not pip/virtualenv is involved. ** **As for entry points - notice in your setup.py file, you have this ** **parameter in your call to setup(): ** **entry_points={ ** **'console_scripts': [ ** **'sample_random=sample_random.try_random:main', ** **], ** **} ** **What this means is: Tell setuptools to create a list of scripts (currently ** **a list of just one). Create a script named "sample_random" that imports ** **the try_random module from the sample_random package and calls the main() ** **function to run it. ** **If you look in the bin directory of the virtual environment where pip ** **install this "package" (distribution of code), you see that setuptools ** **created a file named sample_random with these contents: ** **#!/home/david/temp/env/bin/python3 ** **# EASY-INSTALL-ENTRY-SCRIPT: ** **'sample-random','console_scripts','sample_random' ** **__requires__ = 'sample-random' ** **import re ** **import sys ** **from pkg_resources import load_entry_point ** **if __name__ == '__main__': ** ** ** **sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) ** ** ** **sys.exit( ** ** ** ** ** **load_entry_point('sample-random', 'console_scripts', ** **'sample_random')() ** ** ** **) ** **Notice at the top of the file is a #! line that points to the python ** **interpreter for this virtual environment. The rest of the gobbledygook ** **loads your loads your try_random module and runs that main function in ** **such a way that it looks like it got run from the command line. It uses ** **metadata installed by setuptools in the site-packages of your virtual ** **environment to find the entry point, and to know which package and module ** **to load and which function to run. ** **I hope this helps. I gotta get back to work now! ** **David H ** **On Thursday, November 2, 2017 1:07am, "Steve Gambino" ** **<[3]stevegambino at gmail.com> said: ** **> _______________________________________________ ** **> TriZPUG mailing list ** **> [4]TriZPUG at python.org ** **> [5]https://mail.python.org/mailman/listinfo/trizpug ** **> [6]http://tripython.org is the Triangle Python Users Group ** **> Hi David, ** **> Thank you for your questions. My answers are inline below. I've made ** **> the code available here so that you can look at the setup.py ** **> See [7]https://github.com/sgambino/project-random ** **> ** **> I was a little confused reading your description, mainly because I ** **wasn't ** **> sure when you said "package" whether you meant a distributable unit of ** **> Python code with a setup.py file, or whether you meant "an importable ** **> directory on sys.path containing an __init__.py file". ** **> ** **> ** **> > I see what you mean how my use of terms was confusing. I should have ** **said ** **> a ** **> > distributable unit of Python code with a setup.py file ** **> ** **> ** **> ** **> Is there an importable package directory named "get_random" containing ** **an ** **> __init__.py file? Or is there instead a get_random.py module? ** **> ** **> > Yes, there was an importable package directory named "get_random". ** **Note ** **> that ** **> > since the original post, I renamed the distributable unit to ** **> "sample_random" and ** **> > the importable package directory to "try_random" ** **> ** **> If you have an importable package directory named get_random, then the ** **> behavior you saw is expected. When you import a package, the only names ** **> you see in that package are the ones defined (or imported into) the ** **> __init__.py file itself. To see anything in any other module inside that ** **> package you have to import that explicity, in your main program file or ** **> in ** **> the __init__.py file. ** **> ** **> ** **> ** **> Which form does your get_random program take? There are at least two ** **ways ** **> to distribute Python scripts, one that uses setuptools and console entry ** **> points, and one doesn't. ** **> ** **> > The form of the program uses setuptools and console entry points. This ** **is ** **> > the topic where I think my understanding is the weakest and need help ** **with ** **> ** **> Yes, if you shared your full setup.py file with us, that would probably ** **> answer those questions and more, and would be helpful in diagnosing your ** **> problem. If you would share the full layout of your distributable ** **package ** **> files, that would help too. ** **> ** **> > Yes, of course. See [8]https://github.com/sgambino/project-random ** **> > And note that as mentioned earlier, I renamed the distributable unit ** **from ** **> > to "sample_random" and the python package to "try_random" ** **> > ** **> > I reported earlier that after doing a pip install, I could run the ** **> program from ** **> > command line but if I tried to import the package into a script or ** **into ** **> the ** **> > python REPL itself that I could not see the complete list of the ** **package ** **> > so as to be able call its functions. It appears my issue was with the ** **> > way I was importing it into the namespace. I was declaring "import ** **> sample_random" ** **> > However, in the IRC channel, James (jwhisnant) was helping me, and he ** **> declared the ** **> > import in this form: "from sample_random import try_random" This ** **> appears ** **> > to have resolved the issue. I would like to better understand why so ** **that ** **> > I do not repeat this behavior in the future. I suspect it may be with ** **the ** **> > way I declared the "entry_points" in the setup.py I think need a ** **better ** **> understanding ** **> > of entry points in general and also a clearer understanding of the ** **> semantic elements of the ** **> > form of how they are specified in the setup.py I used the example ** **> setup.py as referenced ** **> > in the tutorials at [9]https://packaging.python.org/ There seems to be ** **> ample documentation ** **> > and commentary in the setup.py concerning entry points but it is still ** **> taking awhile for ** **> > it to become clear enough in my understanding so that I can ** **confidently ** **> say, I truly ** **> > understand. :-) ** **> > ** **> > Thanks, ** **> > Steve Gambino ** **> ** **> On Wed, Nov 1, 2017 at 10:17 PM David Handy <[10]david at handysoftware.com> ** **> wrote: ** **> ** **> > Hi Steve - ** **> > ** **> > ** **> > ** **> > I was a little confused reading your description, mainly because I ** **> > wasn't ** **> > sure when you said "package" whether you meant a distributable unit of ** **> > Python code with a setup.py file, or whether you meant "an importable ** **> > directory on sys.path containing an __init__.py file". ** **> > ** **> > ** **> > ** **> > Is there an importable package directory named "get_random" containing ** **> > an ** **> > __init__.py file? Or is there instead a get_random.py module? ** **> > ** **> > ** **> > ** **> > If you have an importable package directory named get_random, then the ** **> > behavior you saw is expected. When you import a package, the only ** **names ** **> > you see in that package are the ones defined (or imported into) the ** **> > __init__.py file itself. To see anything in any other module inside ** **that ** **> > package you have to import that explicity, in your main program file ** **or ** **> > in ** **> > the __init__.py file. ** **> > ** **> > ** **> > ** **> > Which form does your get_random program take? There are at least two ** **> > ways ** **> > to distribute Python scripts, one that uses setuptools and console ** **entry ** **> > points, and one doesn't. ** **> > ** **> > ** **> > ** **> > Yes, if you shared your full setup.py file with us, that would ** **probably ** **> > answer those questions and more, and would be helpful in diagnosing ** **your ** **> > problem. If you would share the full layout of your distributable ** **> > package ** **> > files, that would help too. ** **> > ** **> > ** **> > ** **> > Thanks, ** **> > ** **> > David H ** **> > ** **> > ** **> > ** **> > ** **> > ** **> > On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" ** **> > <[11]stevegambino at gmail.com> said: ** **> > ** **> > > _______________________________________________ ** **> > > TriZPUG mailing list ** **> > > [12]TriZPUG at python.org ** **> > > [13]https://mail.python.org/mailman/listinfo/trizpug ** **> > > [14]http://tripython.org is the Triangle Python Users Group ** **> > > Hello friends, ** **> > > ** **> > > I'm attempting to learn how to create a pip installable package. So ** **> > far ** **> > the ** **> > > attempt has been relatively successful but for one nagging issue. ** **> I'm ** **> > > hoping if I describe the issue here clearly enough that someone can ** **> > offer ** **> > > pointers to help me get to a resolution. ** **> > > ** **> > > I've created the package (named get_random) successfully with ** **> > setuptools ** **> > > and have been able to do a pip install of it in a virtualenv. ** **> > > ** **> > > The package "get_random" contains a trivial program also named ** **> > > "get_random". The program, "get_random", imports one module, ** **> 'random', ** **> > and ** **> > > it has the functions, main(), get_random() and print_random(). After ** **> > the ** **> > > pip install of the get_random package, I can call the get_random ** **> > program ** **> > > from the command line in the virtualenv and get the expected ** **> results. ** **> > In ** **> > > otherwords, if I run the following in a terminal I get a resulting ** **> > random ** **> > > number, like so: ** **> > > ** **> > > sgambino-m1:~/vnv_for_pip > get_random ** **> > > 0.0259274305036 ** **> > > ** **> > > However, if I try to import the get_random package into a python ** **> REPL ** **> > I ** **> > do ** **> > > not see ** **> > > a complete list of what is in the package. I only see the following: ** **> > > ** **> > > >>> dir(get_random) ** **> > > >>> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> > > '__path__'] ** **> > > ** **> > > but I was expecting to see: ** **> > > ** **> > > >>> dir(get_random) ** **> > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> > > 'get_random', 'main', 'print_random', 'random'] ** **> > > ** **> > > If I try to import the get_random package into a script and run the ** **> > script, ** **> > > I get the following error: ** **> > > ** **> > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> > > Traceback (most recent call last): ** **> > > File "./try_get_random.py", line 5, in ** **> > > get_random.print_random() ** **> > > AttributeError: 'module' object has no attribute 'print_random' ** **> > > ** **> > > Here is some more detail from the REPL that may give a clue. I'm ** **> > wondering ** **> > > if there is something in the setup.py that I haven't ** **> > > defined correctly or not defined at all. I could share that if ** **> someone ** **> > > thinks it is worth a look. The setup.py that I started with ** **> > > was the one that is provided from ** **> > [15]https://github.com/pypa/sampleproject ** **> > > ** **> > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin ** **> > > Type "help", "copyright", "credits" or "license" for more ** **> information. ** **> > > >>> import get_random ** **> > > >>> dir(get_random) ** **> > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> > > '__path__'] ** **> > > >>> print(get_random.__file__) ** **> > > ** **> > ** **> > ** **> ** **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> > > >>> print(get_random.__package__) ** **> > > None ** **> > > >>> print(get_random.__path__) ** **> > > ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> > > ** **> > > If you have bothered to read this far, I hope this has made some ** **> sense ** **> > and ** **> > > I thank you for any ideas you may be willing to share! ** **> > > Steve Gambino ** **> > > -- ** **> > > Best, ** **> > > Steve ** **> > > Hello friends, ** **> > > I'm attempting to learn how to create a pip installable package. So ** **> > far ** **> > > the attempt has been relatively successful but for one nagging ** **> issue. ** **> > I'm ** **> > > hoping if I describe the issue here clearly enough that someone can ** **> > offer ** **> > > pointers to help me get to a resolution. ** **> > > I've created the package (named get_random) successfully with ** **> > setuptools ** **> > > and have been able to do a pip install of it in a virtualenv. ** **> > > The package "get_random" contains a trivial program also named ** **> > > "get_random". The program, "get_random", imports one module, ** **> 'random', ** **> > and ** **> > > it has the functions, main(), get_random() and print_random(). After ** **> > the ** **> > > pip install of the get_random package, I can call the get_random ** **> > program ** **> > > from the command line in the virtualenv and get the expected ** **> results. ** **> > In ** **> > > otherwords, if I run the following in a terminal I get a resulting ** **> > random ** **> > > number, like so: ** **> > > sgambino-m1:~/vnv_for_pip > get_random ** **> > > 0.0259274305036 ** **> > > However, if I try to import the get_random package into a python ** **> REPL ** **> > I ** **> > do ** **> > > not see ** **> > > a complete list of what is in the package. I only see the following: ** **> > > >>> dir(get_random) ** **> > > >>> ['__builtins__', '__doc__', '__file__', '__name__', ** **> > > '__package__', ** **> > > '__path__'] ** **> > > ** **> > > but I was expecting to see: ** **> > > ** **> > > >>> dir(get_random) ** **> > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> > > 'get_random', 'main', 'print_random', 'random'] ** **> > > ** **> > > If I try to import the get_random package into a script and run the ** **> > > script, I get the following error: ** **> > > ** **> > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> > > Traceback (most recent call last): ** **> > > ** File "./try_get_random.py", line 5, in ** **> > > ****** get_random.print_random() ** **> > > AttributeError: 'module' object has no attribute 'print_random' ** **> > > ** **> > > Here is some more detail from the REPL that may give a clue.** I'm ** **> > > wondering if there is something in the setup.py that I haven't ** **> > > defined correctly or not defined at all. I could share that if ** **> someone ** **> > > thinks it is worth a look. The setup.py that I started with ** **> > > was the one that is provided from ** **> > [1][16]https://github.com/pypa/sampleproject ** **> > > Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> > > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin ** **> > > Type "help", "copyright", "credits" or "license" for more ** **> information. ** **> > > >>> import get_random ** **> > > >>> dir(get_random) ** **> > > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', ** **> > > '__path__'] ** **> > > >>> print(get_random.__file__) ** **> > > ** **> > ** **> > ** **> ** **/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> > > >>> print(get_random.__package__) ** **> > > None ** **> > > >>> print(get_random.__path__) ** **> > > ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> > > If you have bothered to read this far, I hope this has made some ** **> sense ** **> > and ** **> > > I thank you for any ideas you may be willing to share! ** **> > > Steve Gambino ** **> > > -- ** **> > > Best,** ** **> > > Steve ** **> > > ** **> > > References ** **> > > ** **> > > Visible links ** **> > > 1. [17]https://github.com/pypa/sampleproject ** **> > > ** **> > _______________________________________________ ** **> > TriZPUG mailing list ** **> > [18]TriZPUG at python.org ** **> > [19]https://mail.python.org/mailman/listinfo/trizpug ** **> > [20]http://tripython.org is the Triangle Python Users Group ** **> > ** **> -- ** **> Best, ** **> Steve ** **> Hi David, ** **> Thank you for your questions.** My answers are inline below.** I've made ** **> the code available here so that you can look at the setup.py ** **> See [1][21]https://github.com/sgambino/project-random ** **> I was a little confused reading your description, mainly because I ** **wasn't ** **> ** **sure when you said "package" whether you meant a distributable unit ** **> of ** **> ** **Python code with a setup.py file, or whether you meant "an ** **importable ** **> ** **directory on sys.path containing an __init__.py file". ** **> > I see what you mean how my use of terms was confusing. I should have ** **> said a ** **> > distributable unit of Python code with a setup.py file ** **> ** **> ** **Is there an importable package directory named "get_random" ** **> containing an ** **> ** **__init__.py file? Or is there instead a get_random.py module? ** **> ** **> > Yes, there was an importable package directory named "get_random".** ** **> Note that ** **> > since the original post, I renamed the distributable unit to ** **> "sample_random" and ** **> > the importable package directory to "try_random" ** **> ** **If you have an importable package directory named get_random, then ** **> the ** **> ** **behavior you saw is expected. When you import a package, the only ** **> names ** **> ** **you see in that package are the ones defined (or imported into) the ** **> ** **__init__.py file itself. To see anything in any other module inside ** **> that ** **> ** **package you have to import that explicity, in your main program ** **file ** **> or in ** **> ** **the __init__.py file. ** **> ** **> ** **Which form does your get_random program take? There are at least ** **two ** **> ways ** **> ** **to distribute Python scripts, one that uses setuptools and console ** **> entry ** **> ** **points, and one doesn't. ** **> ** **> > The form of the program uses setuptools and console entry points. This ** **> is ** **> > the topic where I think my understanding is the weakest and need help ** **> with ** **> ** **Yes, if you shared your full setup.py file with us, that would ** **> probably ** **> ** **answer those questions and more, and would be helpful in diagnosing ** **> your ** **> ** **problem. If you would share the full layout of your distributable ** **> package ** **> ** **files, that would help too. ** **> > Yes, of course. See [2][22]https://github.com/sgambino/project-random ** **> > And note that as mentioned earlier, I renamed the distributable unit ** **> from ** **> >** to "sample_random" and the python package to "try_random" ** **> > ** **> > I reported earlier that after doing a pip install, I could run the ** **> program from ** **> > command line but if I tried to import the package into a script or ** **into ** **> the ** **> > python REPL itself that I could not see the complete list of the ** **package ** **> > so as to be able call its functions.**** It appears my issue was with ** **> the ** **> > way I was importing it into the namespace.** I was declaring "import ** **> sample_random" ** **> > However, in the IRC channel, James (jwhisnant) was helping me, and he ** **> declared the ** **> > import in this form: "from sample_random import try_random"****** This ** **> appears ** **> > to have resolved the issue.** I would like to better understand why so ** **> that ** **> > I do not repeat this behavior in the future.** I suspect it may be ** **with ** **> the ** **> > way I declared the "entry_points" in the setup.py**** I think need a ** **> better understanding ** **> > of entry points in general and also a clearer understanding of the ** **> semantic elements of the ** **> > form of how they are specified in the setup.py**** I used the example ** **> setup.py as referenced ** **> > in the tutorials at [3][23]https://packaging.python.org/**** There seems ** **to ** **> be ample documentation ** **> > and commentary in the setup.py concerning entry points but it is still ** **> taking awhile for ** **> > it to become clear enough in my understanding so that I can ** **confidently ** **> say, I truly ** **> > understand. :-) ** **> > ** **> > Thanks, ** **> > Steve Gambino ** **> On Wed, Nov 1, 2017 at 10:17 PM David Handy <[4][24]david at handysoftware.com> ** **> wrote: ** **> ** **> ** **Hi Steve - ** **> ** **> ** **I was a little confused reading your description, mainly because I ** **> wasn't ** **> ** **sure when you said "package" whether you meant a distributable unit ** **> of ** **> ** **Python code with a setup.py file, or whether you meant "an ** **> importable ** **> ** **directory on sys.path containing an __init__.py file". ** **> ** **> ** **Is there an importable package directory named "get_random" ** **> containing an ** **> ** **__init__.py file? Or is there instead a get_random.py module? ** **> ** **> ** **If you have an importable package directory named get_random, then ** **> the ** **> ** **behavior you saw is expected. When you import a package, the only ** **> names ** **> ** **you see in that package are the ones defined (or imported into) the ** **> ** **__init__.py file itself. To see anything in any other module inside ** **> that ** **> ** **package you have to import that explicity, in your main program ** **> file or in ** **> ** **the __init__.py file. ** **> ** **> ** **Which form does your get_random program take? There are at least ** **> two ways ** **> ** **to distribute Python scripts, one that uses setuptools and console ** **> entry ** **> ** **points, and one doesn't. ** **> ** **> ** **Yes, if you shared your full setup.py file with us, that would ** **> probably ** **> ** **answer those questions and more, and would be helpful in diagnosing ** **> your ** **> ** **problem. If you would share the full layout of your distributable ** **> package ** **> ** **files, that would help too. ** **> ** **> ** **Thanks, ** **> ** **> ** **David H ** **> ** **> ** **On Wednesday, November 1, 2017 3:29pm, "Steve Gambino" ** **> ** **<[5][25]stevegambino at gmail.com> said: ** **> ** **> ** **> _______________________________________________ ** **> ** **> TriZPUG mailing list ** **> ** **> [6][26]TriZPUG at python.org ** **> ** **> [7][27]https://mail.python.org/mailman/listinfo/trizpug ** **> ** **> [8][28]http://tripython.org is the Triangle Python Users Group ** **> ** **> Hello friends, ** **> ** **> ** **> ** **> I'm attempting to learn how to create a pip installable package. ** **> So far ** **> ** **the ** **> ** **> attempt has been relatively successful but for one nagging issue. ** **> I'm ** **> ** **> hoping if I describe the issue here clearly enough that someone ** **> can ** **> ** **offer ** **> ** **> pointers to help me get to a resolution. ** **> ** **> ** **> ** **> I've created the package (named get_random) successfully with ** **> setuptools ** **> ** **> and have been able to do a pip install of it in a virtualenv. ** **> ** **> ** **> ** **> The package "get_random" contains a trivial program also named ** **> ** **> "get_random". The program, "get_random", imports one module, ** **> 'random', ** **> ** **and ** **> ** **> it has the functions, main(), get_random() and print_random(). ** **> After the ** **> ** **> pip install of the get_random package, I can call the get_random ** **> program ** **> ** **> from the command line in the virtualenv and get the expected ** **> results. In ** **> ** **> otherwords, if I run the following in a terminal I get a ** **> resulting ** **> ** **random ** **> ** **> number, like so: ** **> ** **> ** **> ** **> sgambino-m1:~/vnv_for_pip > get_random ** **> ** **> 0.0259274305036 ** **> ** **> ** **> ** **> However, if I try to import the get_random package into a python ** **> REPL I ** **> ** **do ** **> ** **> not see ** **> ** **> a complete list of what is in the package. I only see the ** **> following: ** **> ** **> ** **> ** **> >>> dir(get_random) ** **> ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> ** **> '__path__'] ** **> ** **> ** **> ** **> but I was expecting to see: ** **> ** **> ** **> ** **> >>> dir(get_random) ** **> ** **> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> ** **> 'get_random', 'main', 'print_random', 'random'] ** **> ** **> ** **> ** **> If I try to import the get_random package into a script and run ** **> the ** **> ** **script, ** **> ** **> I get the following error: ** **> ** **> ** **> ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> ** **> Traceback (most recent call last): ** **> ** **> File "./try_get_random.py", line 5, in ** **> ** **> get_random.print_random() ** **> ** **> AttributeError: 'module' object has no attribute 'print_random' ** **> ** **> ** **> ** **> Here is some more detail from the REPL that may give a clue. I'm ** **> ** **wondering ** **> ** **> if there is something in the setup.py that I haven't ** **> ** **> defined correctly or not defined at all. I could share that if ** **> someone ** **> ** **> thinks it is worth a look. The setup.py that I started with ** **> ** **> was the one that is provided from ** **> [9][29]https://github.com/pypa/sampleproject ** **> ** **> ** **> ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on ** **> darwin ** **> ** **> Type "help", "copyright", "credits" or "license" for more ** **> information. ** **> ** **> >>> import get_random ** **> ** **> >>> dir(get_random) ** **> ** **> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> ** **> '__path__'] ** **> ** **> >>> print(get_random.__file__) ** **> ** **> ** **> ** ** **> ** ****/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> ** **> >>> print(get_random.__package__) ** **> ** **> None ** **> ** **> >>> print(get_random.__path__) ** **> ** **> ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> ** **> ** **> ** **> If you have bothered to read this far, I hope this has made some ** **> sense ** **> ** **and ** **> ** **> I thank you for any ideas you may be willing to share! ** **> ** **> Steve Gambino ** **> ** **> -- ** **> ** **> Best, ** **> ** **> Steve ** **> ** **> Hello friends, ** **> ** **> I'm attempting to learn how to create a pip installable package. ** **> So far ** **> ** **> the attempt has been relatively successful but for one nagging ** **> issue. ** **> ** **I'm ** **> ** **> hoping if I describe the issue here clearly enough that someone ** **> can ** **> ** **offer ** **> ** **> pointers to help me get to a resolution. ** **> ** **> I've created the package (named get_random) successfully with ** **> setuptools ** **> ** **> and have been able to do a pip install of it in a virtualenv. ** **> ** **> The package "get_random" contains a trivial program also named ** **> ** **> "get_random". The program, "get_random", imports one module, ** **> 'random', ** **> ** **and ** **> ** **> it has the functions, main(), get_random() and print_random(). ** **> After the ** **> ** **> pip install of the get_random package, I can call the get_random ** **> program ** **> ** **> from the command line in the virtualenv and get the expected ** **> results. In ** **> ** **> otherwords, if I run the following in a terminal I get a ** **> resulting ** **> ** **random ** **> ** **> number, like so: ** **> ** **> sgambino-m1:~/vnv_for_pip > get_random ** **> ** **> 0.0259274305036 ** **> ** **> However, if I try to import the get_random package into a python ** **> REPL I ** **> ** **do ** **> ** **> not see ** **> ** **> a complete list of what is in the package. I only see the ** **> following: ** **> ** **> >>> dir(get_random) ** **> ** **> >>> ['__builtins__', '__doc__', '__file__', '__name__', ** **> ** **> '__package__', ** **> ** **> '__path__'] ** **> ** **> ** **> ** **> but I was expecting to see: ** **> ** **> ** **> ** **> >>> dir(get_random) ** **> ** **> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> ** **> 'get_random', 'main', 'print_random', 'random'] ** **> ** **> ** **> ** **> If I try to import the get_random package into a script and run ** **> the ** **> ** **> script, I get the following error: ** **> ** **> ** **> ** **> ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py ** **> ** **> Traceback (most recent call last): ** **> ** **> ** File "./try_get_random.py", line 5, in ** **> ** **> ****** get_random.print_random() ** **> ** **> AttributeError: 'module' object has no attribute 'print_random' ** **> ** **> ** **> ** **> Here is some more detail from the REPL that may give a clue.** ** **> I'm ** **> ** **> wondering if there is something in the setup.py that I haven't ** **> ** **> defined correctly or not defined at all. I could share that if ** **> someone ** **> ** **> thinks it is worth a look. The setup.py that I started with ** **> ** **> was the one that is provided from ** **> ** **[1][10][30]https://github.com/pypa/sampleproject ** **> ** **> Python 2.7.10 (default, Oct 23 2015, 19:19:21) ** **> ** **> [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on ** **> darwin ** **> ** **> Type "help", "copyright", "credits" or "license" for more ** **> information. ** **> ** **> >>> import get_random ** **> ** **> >>> dir(get_random) ** **> ** **> ['__builtins__', '__doc__', '__file__', '__name__', ** **> '__package__', ** **> ** **> '__path__'] ** **> ** **> >>> print(get_random.__file__) ** **> ** **> ** **> ** ** **> ** ****/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc ** **> ** **> >>> print(get_random.__package__) ** **> ** **> None ** **> ** **> >>> print(get_random.__path__) ** **> ** **> ** **> ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] ** **> ** **> If you have bothered to read this far, I hope this has made some ** **> sense ** **> ** **and ** **> ** **> I thank you for any ideas you may be willing to share! ** **> ** **> Steve Gambino ** **> ** **> -- ** **> ** **> Best,** ** **> ** **> Steve ** **> ** **> ** **> ** **> References ** **> ** **> ** **> ** **> Visible links ** **> ** **> 1. [11][31]https://github.com/pypa/sampleproject ** **> ** **> ** **> _______________________________________________ ** **> TriZPUG mailing list ** **> [12][32]TriZPUG at python.org ** **> [13][33]https://mail.python.org/mailman/listinfo/trizpug ** **> [14][34]http://tripython.org is the Triangle Python Users Group ** **> ** **> -- ** **> Best,** ** **> Steve ** **> ** **> References ** **> ** **> Visible links ** **> 1. [35]https://github.com/sgambino/project-random ** **> 2. [36]https://github.com/sgambino/project-random ** **> 3. [37]https://packaging.python.org/ ** **> 4. mailto:[38]david at handysoftware.com ** **> 5. mailto:[39]stevegambino at gmail.com ** **> 6. mailto:[40]TriZPUG at python.org ** **> 7. [41]https://mail.python.org/mailman/listinfo/trizpug ** **> 8. [42]http://tripython.org/ ** **> 9. [43]https://github.com/pypa/sampleproject ** **> 10. [44]https://github.com/pypa/sampleproject ** **> 11. [45]https://github.com/pypa/sampleproject ** **> 12. mailto:[46]TriZPUG at python.org ** **> 13. [47]https://mail.python.org/mailman/listinfo/trizpug ** **> 14. [48]http://tripython.org/ ** **> References ** **Visible links ** **1. [49]https://github.com/sgambino/project-random.git _______________________________________________ TriZPUG mailing list [50]TriZPUG at python.org [51]https://mail.python.org/mailman/listinfo/trizpug [52]http://tripython.org is the Triangle Python Users Group -- Best,** Steve References Visible links 1. mailto:david at handysoftware.com 2. https://github.com/sgambino/project-random.git 3. mailto:stevegambino at gmail.com 4. mailto:TriZPUG at python.org 5. https://mail.python.org/mailman/listinfo/trizpug 6. http://tripython.org/ 7. https://github.com/sgambino/project-random 8. https://github.com/sgambino/project-random 9. https://packaging.python.org/ 10. mailto:david at handysoftware.com 11. mailto:stevegambino at gmail.com 12. mailto:TriZPUG at python.org 13. https://mail.python.org/mailman/listinfo/trizpug 14. http://tripython.org/ 15. https://github.com/pypa/sampleproject 16. https://github.com/pypa/sampleproject 17. https://github.com/pypa/sampleproject 18. mailto:TriZPUG at python.org 19. https://mail.python.org/mailman/listinfo/trizpug 20. http://tripython.org/ 21. https://github.com/sgambino/project-random 22. https://github.com/sgambino/project-random 23. https://packaging.python.org/**** 24. mailto:david at handysoftware.com 25. mailto:stevegambino at gmail.com 26. mailto:TriZPUG at python.org 27. https://mail.python.org/mailman/listinfo/trizpug 28. http://tripython.org/ 29. https://github.com/pypa/sampleproject 30. https://github.com/pypa/sampleproject 31. https://github.com/pypa/sampleproject 32. mailto:TriZPUG at python.org 33. https://mail.python.org/mailman/listinfo/trizpug 34. http://tripython.org/ 35. https://github.com/sgambino/project-random 36. https://github.com/sgambino/project-random 37. https://packaging.python.org/ 38. mailto:david at handysoftware.com 39. mailto:stevegambino at gmail.com 40. mailto:TriZPUG at python.org 41. https://mail.python.org/mailman/listinfo/trizpug 42. http://tripython.org/ 43. https://github.com/pypa/sampleproject 44. https://github.com/pypa/sampleproject 45. https://github.com/pypa/sampleproject 46. mailto:TriZPUG at python.org 47. https://mail.python.org/mailman/listinfo/trizpug 48. http://tripython.org/ 49. https://github.com/sgambino/project-random.git 50. mailto:TriZPUG at python.org 51. https://mail.python.org/mailman/listinfo/trizpug 52. http://tripython.org/ From glennfmatthews at gmail.com Wed Nov 1 17:18:49 2017 From: glennfmatthews at gmail.com (Glenn Matthews) Date: Wed, 1 Nov 2017 17:18:49 -0400 Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: References: Message-ID: <7688C144-9617-473E-8FB9-D60352EB8DA0@gmail.com> Hi Steve, Can you share your project?s directory and file structure? I have a few ideas but don?t want to send you off track. ? Thanks, Glenn Sent from a touchscreen keyboard - please forgive brevity and typos! ? > On Nov 1, 2017, at 3:29 PM, Steve Gambino wrote: > > Hello friends, > I'm attempting to learn how to create a pip installable package. So far > the attempt has been relatively successful but for one nagging issue. I'm > hoping if I describe the issue here clearly enough that someone can offer > pointers to help me get to a resolution. > I've created the package (named get_random) successfully with setuptools > and have been able to do a pip install of it in a virtualenv. > The package "get_random" contains a trivial program also named > "get_random". The program, "get_random", imports one module, 'random', and > it has the functions, main(), get_random() and print_random(). After the > pip install of the get_random package, I can call the get_random program > from the command line in the virtualenv and get the expected results. In > otherwords, if I run the following in a terminal I get a resulting random > number, like so: > sgambino-m1:~/vnv_for_pip > get_random > 0.0259274305036 > However, if I try to import the get_random package into a python REPL I do > not see > a complete list of what is in the package. I only see the following: >>>> dir(get_random) >>>> ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] > > but I was expecting to see: > >>>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > 'get_random', 'main', 'print_random', 'random'] > > If I try to import the get_random package into a script and run the > script, I get the following error: > > ncralsgambino-m1:~/vnv_for_pip > ./try_get_random.py > Traceback (most recent call last): > ** File "./try_get_random.py", line 5, in > ****** get_random.print_random() > AttributeError: 'module' object has no attribute 'print_random' > > Here is some more detail from the REPL that may give a clue.** I'm > wondering if there is something in the setup.py that I haven't > defined correctly or not defined at all. I could share that if someone > thinks it is worth a look. The setup.py that I started with > was the one that is provided from [1]https://github.com/pypa/sampleproject > Python 2.7.10 (default, Oct 23 2015, 19:19:21) > [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin > Type "help", "copyright", "credits" or "license" for more information. >>>> import get_random >>>> dir(get_random) > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', > '__path__'] >>>> print(get_random.__file__) > /Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random/__init__.pyc >>>> print(get_random.__package__) > None >>>> print(get_random.__path__) > ['/Users/sgambino/vnv_for_pip/lib/python2.7/site-packages/get_random'] > If you have bothered to read this far, I hope this has made some sense and > I thank you for any ideas you may be willing to share! > Steve Gambino > -- > Best,** > Steve > > References > > Visible links > 1. https://github.com/pypa/sampleproject > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group From cbc at unc.edu Fri Nov 3 10:36:55 2017 From: cbc at unc.edu (Calloway, Chris) Date: Fri, 3 Nov 2017 14:36:55 +0000 Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: <7688C144-9617-473E-8FB9-D60352EB8DA0@gmail.com> References: <7688C144-9617-473E-8FB9-D60352EB8DA0@gmail.com> Message-ID: Post from unsubscribed email address accepted this once. Please use your subscribed email address to post. This is how we keep spam out. -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 On 11/1/17, 5:18 PM, "TriZPUG on behalf of Glenn Matthews" wrote: Hi Steve, Can you share your project?s directory and file structure? I have a few ideas but don?t want to send you off track. ? Thanks, Glenn From stevegambino at gmail.com Fri Nov 3 17:08:44 2017 From: stevegambino at gmail.com (Steve Gambino) Date: Fri, 03 Nov 2017 21:08:44 +0000 Subject: [TriPython] Problems with import after attempting to create pip installable package In-Reply-To: References: <7688C144-9617-473E-8FB9-D60352EB8DA0@gmail.com> Message-ID: Glenn, See https://github.com/pypa/sampleproject but also see Dave's posts as between his and Jame's help on IRC we've got it resolved. Thanks for your interest! Steve On Fri, Nov 3, 2017 at 11:14 AM Calloway, Chris wrote: > Post from unsubscribed email address accepted this once. Please use your > subscribed email address to post. This is how we keep spam out. > > -- > Sincerely, > > Chris Calloway > Applications Analyst > University of North Carolina > Renaissance Computing Institute > (919) 599-3530 > > > On 11/1/17, 5:18 PM, "TriZPUG on behalf of Glenn Matthews" > glennfmatthews at gmail.com> wrote: > > Hi Steve, > > Can you share your project?s directory and file structure? I have a > few ideas but don?t want to send you off track. ? > > Thanks, > > Glenn > > > _______________________________________________ > TriZPUG mailing list > TriZPUG at python.org > https://mail.python.org/mailman/listinfo/trizpug > http://tripython.org is the Triangle Python Users Group > -- Best, Steve -------------- next part -------------- Glenn, See [1]https://github.com/pypa/sampleproject** but also see Dave's posts as between his and Jame's help on IRC we've got it resolved. Thanks for your interest! Steve On Fri, Nov 3, 2017 at 11:14 AM Calloway, Chris <[2]cbc at unc.edu> wrote: Post from unsubscribed email address accepted this once. Please use your subscribed email address to post. This is how we keep spam out. -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute [3](919) 599-3530 On 11/1/17, 5:18 PM, "TriZPUG on behalf of Glenn Matthews" wrote: ** ** Hi Steve, ** ** Can you share your project***s directory and file structure? I have a few ideas but don***t want to send you off track. **** ** ** Thanks, ** ** Glenn _______________________________________________ TriZPUG mailing list [6]TriZPUG at python.org [7]https://mail.python.org/mailman/listinfo/trizpug [8]http://tripython.org is the Triangle Python Users Group -- Best,** Steve References Visible links 1. https://github.com/pypa/sampleproject 2. mailto:cbc at unc.edu 3. file:///tmp/tel:(919)%20599-3530 4. mailto:unc.edu at python.org 5. mailto:glennfmatthews at gmail.com 6. mailto:TriZPUG at python.org 7. https://mail.python.org/mailman/listinfo/trizpug 8. http://tripython.org/ From bgerard at gmail.com Sun Nov 5 21:11:30 2017 From: bgerard at gmail.com (Brian Gerard) Date: Sun, 5 Nov 2017 21:11:30 -0500 Subject: [TriPython] Lightning talk, anyone? Message-ID: Hey everyone- TriLUG (the Triangle Linux Users Group) is having a lightning talks only meeting this Thursday, 11/9, and we're fishing for speakers. :) Since lightning talks are such an integral part of the TriPython culture, I wanted to reach out and see if any of you fine folks might want to come on by and present one. The details are on the site at https://trilug.org/2017-11-09/lightning-talks, including a link to the sign-up sheet. But for the basics, it's 7:00 PM (pizza starts at 6:45), at the College of Textiles on the NCSU Centennial Campus (map link is on the page). The sign-up sheet only has options for 5 or 10 minutes, but that's just so we can guess about how much time we need - if you have something that runs over or under those, that's just fine. Even if you don't want to present, come on by and see what other things we may have to show! Hope to see you there- Brian From cbc at unc.edu Mon Nov 6 12:23:47 2017 From: cbc at unc.edu (Calloway, Chris) Date: Mon, 6 Nov 2017 17:23:47 +0000 Subject: [TriPython] Reminder: Two Project Nights This Week and Other Good News Message-ID: <0FD6C08B-F384-4D65-94A5-9F6B50112F47@unc.edu> We have back to back project nights this week in Raleigh and Chapel Hill: Tuesday in Raleigh: http://tripython.org/Members/sgambino/nov-17-rpn/ Wednesday in Chapel Hill: http://tripython.org/Members/cbc/nov-17-chpn Be sure to bring your laptop. The one in Chapel Hill will be in a different room from usual, but still on the 5th floor. Just follow the signs when you get off the elevator. If you are leaving from and returning to Chapel Hill to go to the one in Raleigh, please contact me offline. Good news. Even though PyCon is in Cleveland this year, PyOhio is still happening in Columbus on the usual last weekend of July: https://twitter.com/PyOhio/status/927359545747361793 PyTennessee is also happening in February: https://www.pytennessee.org/ -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 -------------- next part -------------- We have back to back project nights this week in Raleigh and Chapel Hill: Tuesday in Raleigh: [1]http://tripython.org/Members/sgambino/nov-17-rpn/ Wednesday in Chapel Hill: [2]http://tripython.org/Members/cbc/nov-17-chpn Be sure to bring your laptop. The one in Chapel Hill will be in a different room from usual, but still on the 5^th floor. Just follow the signs when you get off the elevator. If you are leaving from and returning to Chapel Hill to go to the one in Raleigh, please contact me offline. Good news. Even though PyCon is in Cleveland this year, PyOhio is still happening in Columbus on the usual last weekend of July: [3]https://twitter.com/PyOhio/status/927359545747361793 PyTennessee is also happening in February: [4]https://www.pytennessee.org/ -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 References Visible links 1. http://tripython.org/Members/sgambino/nov-17-rpn/ 2. http://tripython.org/Members/cbc/nov-17-chpn 3. https://twitter.com/PyOhio/status/927359545747361793 4. https://www.pytennessee.org/ From cbc at unc.edu Thu Nov 16 17:30:26 2017 From: cbc at unc.edu (Calloway, Chris) Date: Thu, 16 Nov 2017 22:30:26 +0000 Subject: [TriPython] TriPython November 2017 Meeting: Web UI Automation with Selenium for Beginners Message-ID: <5DD4CAD8-873A-4AF9-939C-0B5094D8803D@unc.edu> Thanks to an eagle eyed member, a typo was spotted in the announcement below. The meeting is *Thursday* the 16th, today. The announcement was correct on tripython.org and on meetup.com. Hopefully this didn?t throw you off. -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 On 10/30/17, 2:58 PM, "TriZPUG on behalf of Calloway, Chris" wrote: http://tripython.org/Members/sgambino/nov-17-mtg When: Wednesday, November 16, 7-9pm Where: WebAssign NCSU Centennial Campus 1791 Varsity Drive Suite 200 Raleigh What: This talk will cover web user interface automation using Selenium with a focus on the Python programming language. Attendants will learn how to easily gather web UI information, record their actions and play them back via Selenium IDE, then learn how to write Python code to perform the same actions and finally how to use your automation with py.test. Another topic that will be discussed, time allowing, will be how to use SauceLabs to execute automated tests on multiple types of operating systems and web browser combinations. Og Maciel presents. Og is a Senior Manager of Quality Engineering for the Red Hat Satellite team. He has spent the last 5+ years building a team of black belt quality engineers responsible for the automation of complex systems and delivering quality products through the use of continuous delivery of processes. He is also a podcaster, a dad, and an avid reader. The November meeting date is shifted from the normal fourth to the third Thursday in order to work around the holidays. Extemporaneous "lightning talks" of 5-10 minute duration are also welcome and don't need to be pre-announced. Plenty of free after hours parking is available in the upper level of the deck behind WebAssign (turn through the median just before the intersection of Varsity and Main Campus Drives). If the door is locked, call the number posted on the door. An after-meeting location for food and beverage will be decided at the meeting (usually BaDa Wings at Mission Valley). -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 From omaciel at ogmaciel.com Mon Nov 20 10:38:21 2017 From: omaciel at ogmaciel.com (Og Maciel) Date: Mon, 20 Nov 2017 10:38:21 -0500 Subject: [TriPython] Slides for November presentation Message-ID: Thank you all who came to my presentation last week! Slides for my presentation can be found here: https://speakerdeck.com/omaciel/web-ui-automation-with-selenium-for-beginners -- Og Maciel - GPG Keys: CD03D583 omaciel at ogmaciel.com https://omaciel.github.io From cbc at unc.edu Mon Nov 20 15:49:52 2017 From: cbc at unc.edu (Calloway, Chris) Date: Mon, 20 Nov 2017 20:49:52 +0000 Subject: [TriPython] December Meeting Needs Speaker Message-ID: <4BB28BA0-71B9-4983-BBDD-B0BEB09D13F9@unc.edu> We have a meeting at Caktus in Durham in three weeks on Thursday, Devember 14. I?d like to hear someone volunteer to be the featured speaker. -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 -------------- next part -------------- We have a meeting at Caktus in Durham in three weeks on Thursday, Devember 14. I'd like to hear someone volunteer to be the featured speaker. -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 From cbc at unc.edu Mon Nov 20 10:35:34 2017 From: cbc at unc.edu (Calloway, Chris) Date: Mon, 20 Nov 2017 15:35:34 +0000 Subject: [TriPython] Come be my co-worker Message-ID: https://unc.peopleadmin.com/postings/130670 -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 -------------- next part -------------- https://unc.peopleadmin.com/postings/130670 -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 From cbc at unc.edu Wed Nov 29 09:18:26 2017 From: cbc at unc.edu (Calloway, Chris) Date: Wed, 29 Nov 2017 14:18:26 +0000 Subject: [TriPython] The PSF awarded $170, 000 grant from Mozilla Open Source Program to improve sustainability of PyPI Message-ID: http://pyfound.blogspot.com/2017/11/the-psf-awarded-moss-grant-pypi.html -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530 -------------- next part -------------- http://pyfound.blogspot.com/2017/11/the-psf-awarded-moss-grant-pypi.html -- Sincerely, Chris Calloway Applications Analyst University of North Carolina Renaissance Computing Institute (919) 599-3530