Home python Connecting a python module from another folder on Linux

Connecting a python module from another folder on Linux




In windows, I could connect a module from a nearby folder:

from libraries import OracleDB as ora

Where libraries is the name of the folder. Transferred to redhat and the same line began to swear, they say, there is no such module – libraries. Is import different on linux, and if so, how to import correctly?

Answer 1, authority 100%

Here is what D.S. Kickback (“The Python Programming Language”):

When a module is imported, such as spam, the interpreter looks for a file with
named ‘spam.py’ in the current directory, then in the directories specified in
environment variable PYTHONPATH, then in platform dependent paths
by default.

The directories being searched are stored in a variable
sys.path. Thus, Python programs can change paths.
search for modules while they are running.

Just start Python and run two commands:

& gt; & gt; & gt; import sys
& gt; & gt; & gt; print (sys.path)

and you will see everything.

How to import from a nearby folder?

In the same book, just below, there is an answer to this question of yours:

The sys.path variable contains a list of strings with directory names, in
which modules are searched for. It is initialized from the value
the environment variable PYTHONPATH and the built-in default.
You can change its value using standard operations with

& gt; & gt; & gt; import sys
& gt; & gt; & gt; sys.path.append ('/ ufs / guido / lib / python')

Well, you still have a book, read it!

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions