首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在macos中由启动can脚本触发时无法导入Python模块

在macos中由启动can脚本触发时无法导入Python模块
EN

Stack Overflow用户
提问于 2017-03-26 22:26:39
回答 1查看 280关注 0票数 1

The python program(apple.py) which wanted to be triggered by launchctl script,written under python2.7 in anaconda

The launchctl plist script(com.tushare.refreshall.plist) which was used to trigger the python program

我尝试使用plist脚本来启动我的python程序,但徒劳无功,在程序中,我导入了一个包tushare,但在日志文件"stderr“中返回"ImportError: No module named tushare”,这个包可以成功导入到用anaconda编写的python程序中。

结果:

代码语言:javascript
复制
Traceback (most recent call last):

  File "/Users/jacksonshawn/PythonCodes/apple.py", line 8, in <module>
import tushare as ts

ImportError: No module named tushare

我猜可能是因为plist脚本中缺少"EnvironmentVariables“参数,但我不知道如何修改plist脚本来确定problem.Every时间,我做了以下操作来执行用Plist脚本检查过的script.Syntax,它可以执行。

代码语言:javascript
复制
"launchctl unload -w com.tushare.refreshall.plist"

"launchctl load -w com.tushare.refreshall.plist"

"launchctl start com.tushare.refreshall.plist"
EN

回答 1

Stack Overflow用户

发布于 2019-12-05 03:18:24

您正在启动的启动into服务可能不会与您登录到终端时所处的环境共享,包括anaconda配置。

你可以通过调整plist的ProgramArguments键来修复这个问题,首先通过bash键运行你想要的任何东西,并在目标程序之前包含conda激活。以下是在名为py36的conda环境中运行emacs守护进程的示例

代码语言:javascript
复制
  <key>ProgramArguments</key>
  <array>
    <string>bash</string>
    <string>-c</string>
    <string>source /Users/username/anaconda3/etc/profile.d/conda.sh; conda activate py36; /usr/local/opt/emacs/bin/emacs --fg-daemon</string>
  </array>

这里假设您是在/Users/username/anaconda3中安装了anaconda的username。根据您的具体情况进行调整,包括conda环境名称。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43029977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档