[Tutor] Running programs that import 3rd party packages installed using pip.

Roger B. Atkins rba2124 at gmail.com
Thu Oct 4 10:15:01 EDT 2018


That's very helpful, thanks. After reading the Tutor information last
night, I wrote a little program I named sysinfo. The code run line by
line in a Spyder console yields:

In [3]: sys.path
Out[3]:
['',
 'C:\\Users\\rba21\\Anaconda3\\python36.zip',
 'C:\\Users\\rba21\\Anaconda3\\DLLs',
 'C:\\Users\\rba21\\Anaconda3\\lib',
 'C:\\Users\\rba21\\Anaconda3',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\win32',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\Pythonwin',
 'C:\\Users\\rba21\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\rba21\\.ipython']

In [4]: sys.version
Out[4]: '3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC
v.1900 64 bit (AMD64)]'

In [5]: sys.platform
Out[5]: 'win32'

I'll have to do more research to figure out which folders I need to
add given that '\site-packages'
is already included, but at least I won't be looking at the wrong path variable.
On Thu, Oct 4, 2018 at 6:54 AM Mats Wichmann <mats at wichmann.us> wrote:
>
> On 10/03/2018 09:20 PM, Roger B. Atkins wrote:
> > System:  Windows 10, Anaconda, Python 3, Spyder3
> >
> > Problem: Running programs that import requests, pyperclip, bs4 and/or
> > other modules from 3rd party packages works fine within Spyder IDE,
> > but not from command line, or Win/R. The error message indicates no
> > such module. Therefore, my programs crash at the import statement. In
> > contrast, programs using built in modules work fine everywhere.
> > Questions: Which file needs to be found? Is this a path problem?
> >
> > Efforts to solve problem:  After making sure I had correctly typed the
> > module names, my second guess was that it is a path problem, so I used
> > win explorer to locate the module files. I also went to the command
> > line and used "pip show modname".
> > The search using win explorer revealed module files in multiple
> > directories, so part of the problem may be that I don't know which
> > file the import statement needs to be able to find.
> > Based on results using pip show modname, the modules were installed in:
> > Anaconda3\lib\site-packages.
> > In fact, as shown in Win Explorer, they are in sub folders under
> > \site-packages, and there are 'regular' py files as well as compiled
> > files. (I'm a beginner, and thought Python was interpreted?)
> >
> > I changed my system path variable to include:
> > C:\Users\rba21\Anaconda3\lib\site-packages    # Result: same error message
> > C:\Users\rba21\Anaconda3\lib\site-packages\pyperclip  # Result: same
> > error message
> > I tried adding the sub folders down to __pycache__  but got the same
> > error message.
> >
> > I did some web searches, but didn't find anything that enabled me to
> > fix the problem.
>
> Write this simple program and run it from the "command line":
>
> import sys
> print(sys.path)
>
> those are the places Python will look for modules when importing. you
> can add to sys.path in your program, or if you define PYTHONPATH, its
> contents will show up in sys.path.
>
> if you now do the same thing in a program running inside Spyder, you'll
> probably see differences in sys.path.
>
> as Alan said, the system/user environment paths have nothing to do with
> Python's module importing.
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list