Py学习  »  Python

即使在PYTHONPATH中添加了文件夹,也找不到Python模块

jxw • 3 年前 • 147 次点击  

假设我有2个Python项目文件夹。文件夹1称为module2,位于 /Users/jianxiongwu/Documents/Python/Github/module2 在folder1中有一个名为 test.py 包含以下代码。当我运行下面的代码时,我首先用 source env/bin/activate

import sys
sys.path.append('/Users/jianxiongwu/Documents/Python/Github/testPDF')
import module1
module1.test1()

第二个Python项目文件夹位于 /Users/jianxiongwu/Documents/Python/Github/testPDF 包含 module1.py 下面是几行:

def test1():
    print('test from module 1')%           

当我这么做的时候 sys.path.append 我可以 import module1 .我想去掉这一行,在我的MAC OS版本上改用PYTHONPATH。12.1. 然后我编辑了 bash_profile "/Users/jianxiongwu/Documents/Python/Github/testPDF" 在里面 PYTHONPATH .在评论了 sys.path.append('/Users/jianxiongwu/Documents/Python/Github/testPDF') 我得到一个模块未找到错误。

cat ~/.bash_profile
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

#Setting path to the POS
export PYTHONPATH=["/Users/jianxiongwu/Documents/Python/Github/POS/env/lib/python3.7/site-packages",
"/Users/jianxiongwu/Documents/Python/Github/testPDF"]

export PATH="/usr/local/opt/mysql-client/bin:$PATH"
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/132821
 
147 次点击