New to Python and understanding problem
Peter Otten
__peter__ at web.de
Mon Jan 29 13:29:20 EST 2018
Michelle Konzack wrote:
> Hello *,
>
> because I am runing into problems with SOME python based programs, I the
> this as opportunity to learn python (after ASM, C, BaSH, CP/M, COBOL,
> JS, PHP and perl).
>
>
> OK, I tried to install "blueman" (Bluetooth Manager) on my Debian 9.2
> (Stretch system and discovered a problem:
>
> ----[ c 'blueman-applet' ]----------------------------------------------
> Traceback (most recent call last):
> File "./blueman-applet", line 15, in <module>
> from blueman.Functions import create_logger, create_parser,
> set_proc_title
> ImportError: No module named 'blueman'
> ------------------------------------------------------------------------
>
> So ist does not find the module and this are the fist 16 lines of the
> python script:
>
> ----[ '/usr/bin/blueman-applet' ]---------------------------------------
> #!/usr/bin/env python3
> # coding=utf-8
>
> import sys
> import os
> import signal
> import logging
>
> # support running uninstalled
> _dirname = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
> if 'BLUEMAN_SOURCE' in os.environ:
> sys.path = [_dirname, os.path.join(_dirname, 'module', '.libs')] +
> sys.path
> os.environ["GSETTINGS_SCHEMA_DIR"] = os.path.join(_dirname, "data")
>
> from blueman.Functions import create_logger, create_parser, set_proc_title
> from blueman.main.Applet import BluemanApplet
> ------------------------------------------------------------------------
>
> I think, that I have found the error here:
>
> sys.path = [_dirname, os.path.join(_dirname, 'module', '.libs')] +
> sys.path
>
> because there is written in
>
> ----[ '/usr/lib/python-3.5/os.py' ]-------------------------------------
> To get a full path (which begins with top) to a file or directory in
> dirpath, do os.path.join(dirpath, name).
> ------------------------------------------------------------------------
>
> Hence, os.path.join() has only 2 parameters and not 3.
os.path.join() accepts one or more parameters as you can verify in the
interactive interpreter:
$ python3
Python 3.4.3 (default, Nov 28 2017, 16:41:13)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.join()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: join() missing 1 required positional argument: 'a'
>>> os.path.join("foo")
'foo'
>>> os.path.join("foo", "bar")
'foo/bar'
>>> os.path.join("foo", "bar", "baz")
'foo/bar/baz'
>
> The module "blueman" is a subdirectory and the full path is
>
> /usr/lib/python-3.5/site-packages/blueman
>
> So, how can I correct this problem?
Random idea: Did you set the BLUEMAN_SOURCE environment variable? If so, try
to unset it. If that doesn't help insert the line
print(sys.path)
into the blueman-applet script right after the line
import sys
This should print a list of paths that Python searches for modules. Does
this list contain the
/usr/lib/python-3.5/site-packages
directory? If it doesn't, what's actually in that list?
> And then here is anoter thing which I do not understand becasue I have
> not found it in the Tutorial:
>
> What do the [ ... ] mean or what function is it?
If it occurs in Python source code it is a list literal
>>> a = [1, 10, 100]
>>> type(a)
<class 'list'>
or a list comprehension
>>> b = [x*x for x in a]
>>> b
[1, 100, 10000]
Both should be mentioned in every Python tutorial.
More information about the Python-list
mailing list