V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
oh8
V2EX  ›  Python

关于 python 在 mac 下自定义模块目录的问题

  •  
  •   oh8 · 2016-11-03 15:15:54 +08:00 · 3692 次点击
    这是一个创建于 2730 天前的主题,其中的信息可能已经有所发展或是发生改变。

    要如何在 terminal 的环境下添加自定目录?

    试着在 .profile 文件里面添加

    PYTHONPATH="/Users/xxxx/xxxx:$PYTHONPATH"
    export PYTHONPATH
    

    发现在 sublime text 里面可以正常运行,但在 terminal 下就报错 ImportError: No module named xxx

    最新版 mac , python2.7

    5 条回复    2016-11-04 13:29:04 +08:00
    stamaimer
        1
    stamaimer  
       2016-11-03 15:43:54 +08:00 via iPhone
    import sys
    sys.path.append("path2module")
    v2014
        2
    v2014  
       2016-11-03 16:24:55 +08:00
    干嘛不把他打包,到处可以用
    写个 setup.py
    pip install -e .
    oh8
        3
    oh8  
    OP
       2016-11-03 16:50:50 +08:00
    @stamaimer
    这个确实可以解决问题,但感觉不太优雅啊。。

    @v2014
    因为导入的那个 py 文件也一直在改变
    lcj2class
        4
    lcj2class  
       2016-11-03 23:16:22 +08:00 via iPhone
    就是 2 楼说的方法, e 指定了是用开发者模式安装,会直接用源文件的
    oh8
        5
    oh8  
    OP
       2016-11-04 13:29:04 +08:00
    原来如此,谢了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3232 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:07 · PVG 22:07 · LAX 07:07 · JFK 10:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.