python-2.7 - Installed package in project and getting error
问题描述
I have install package in my personal folder
sudo pip install boto3 -t ./lib
boto3 install in lib folder
Project
--> lib
--> boto3 package
--> __init__.py
--> python script
--> read.py
lib has one package boto3
Now i am accessing boto3 in python script read.py import lib.boto3
Getting error
File "read.py", line 5, in <module>
from lib import boto3
File "/var/www/html/packages/lib/boto3/__init__.py", line 16, in
<module>
from boto3.session import Session
but when i try to place this file(read.py) in lib folder then its import boto3 without an error why?
after place read.py file in lib
Project
--> lib
--> boto3 package
--> __init__.py
--> read.py
--> python script
解决方案
Add path in your PYTHONPATH
import os
path = os.path.dirname(os.path.realpath(__file__))
user_home = os.environ["HOME"]
os.environ["PYTHONPATH"] = path+'/lib'
import sys
sys.path.append( path+'/lib')
import boto3
推荐阅读
- python - 选择带有 where 条件 Panda DataFrame 的多列
- php - Apache2 is not working
- reactjs - 从公有子网连接到私有子网中的 API 端点
- android - Android Kotlin 底部导航栏
- python - Python SQLAlchemy 关系不存在
- javascript - Vuex/Vuejs:在 vuex 存储中访问 localStorage
- javascript - 使用鼠标拖动更改背景图像位置,如 facebook 封面照片
- javascript - PHP如何防止页面加载时自动提交表单或使用F5刷新
- javascript - 需要了解passport.js本地策略
- javascript - Vuejs2 passing dynamic data within data