I'm trying to add /home/garrett/bin/libpy/ to my python path so I can import my own libraries, I would also prefer not to overwrite the default python path but rather append my own path to the default. When I try to echo $PYTHONPATH or $PYTHONHOME I get nothing and even if I were to set it on the command line it wouldn't remain after the next reboot. I don't know where the config file for this is. Here's what the man pages had to say.

              Change  the  location  of the standard Python libraries.  By default, the libraries are searched in ${prefix}/lib/python<version> and ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix} are installa‚Äź
              tion-dependent directories, both defaulting to /usr/local.  When $PYTHONHOME is set to a single directory, its value replaces both ${prefix} and ${exec_prefix}.  To specify different values for these,  set  $PYTHONHOME
              to ${prefix}:${exec_prefix}.

              Augments  the default search path for module files.  The format is the same as the shell's $PATH: one or more directory pathnames separated by colons.  Non-existent directories are silently ignored.  The default search
              path is installation dependent, but generally begins with ${prefix}/lib/python<version> (see PYTHONHOME above).  The default search path is always appended to $PYTHONPATH.  If a script argument is given, the  directory
              containing the script is inserted in the path in front of $PYTHONPATH.  The search path can be manipulated from within a Python program as the variable sys.path.

Recommended Answers

All 3 Replies



at the end of the file /home/garrett/.bashrc

Then restart the terminal.

Since the current value of $PYTHONPATH seems to be null I devided that overwritting it wasn't such a bad thing, my .bashrc file currently has this line -> export PYTHONPATH="$HOME/bin.libpy" I have a very small program I'v written along with my imported library file but I'm still having problems.

Python program 'tags' in /home/garrett/bin/

#!/usr/bin/env python3

import sys
import MetaMP3.py

file = sys.argv[1]
tags = get_tags_mp3(file)

for i in tags:

Current librar file MetaMP3.py in /home/garrett/bin/libpy/

#!/usr/bin/env python3

import sys

def get_tags_mp3(song):
    f = open(song, 'rb')
    position = -95
    tag = b''
    counter = 0
    tags = []

    for i in range(0,2):
        f.seek(position, 2)
        line = f.read(30)
        position = -65

        while line[counter] is not 0:
            tag = tag + line[counter:counter + 1]
            counter = counter + 1

        counter = 0
        tag = tag.decode('utf-8')
        tag = b''

    return tags


garrett@mint-desktop ~/Downloads $ tags The\ Rains\ of\ Castamere.mp3 
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/garrett/bin/tags", line 4, in <module>
    import MetaMP3.py
ImportError: No module named 'MetaMP3.py'; 'MetaMP3' is not a package

import MetaMP3.py should be import MetaMP3.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.