简体   繁体   中英

Python Appegine sys.path.append() doesnt work

I'm not finding a correct way to add "libs" to my system path. So, I want to import:

from lib1 import ClassX

In main.py:

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), "libs"))

My project schema is:

project
--- app1
--- libs
------ lib1.py
------ __init__.py
--- main.py

How can I achieve this?

UPDATE! I have used. Same error:

sys.path.append("/home/alpocr/path-to-project/libs")

add os.path.abspath to your code:

import os, sys
sys.path.append(
   os.path.join(
      os.path.abspath(os.path.dirname(__file__),
      "libs"
   )
)

A more comprehensive and complete solution is available via the Darth Vendor utility. You can read about some of the challenges and pitfalls with a simple sys.path.append here .

Hopefully in the near future it will be easier to manage 3rd party packages on app engine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM