问题描述
大家好,这是我对StackOverflow的第一个问题,我希望它对大家都有益.我最近开始使用TMUX,但在解决我的机器学习问题集时遇到问题.
Hi everyone this is my first question on StackOverflow and I hope it finds everyone well. I recently started using TMUX and I'm having a problem using it for a machine learning problem set I have.
我正在使用python创建程序,并且正在使用sklearn模块.基本上,当我在终端中运行TMUX会话中的代码时,一切正常.但是,当我启动TMUX会话并运行代码时,出现以下错误.
I'm creating a program using python and I'm using the sklearn module. Basically when I run the code in the terminal out my TMUX session, everything works fine. However, when I start a TMUX session and run the code, I get the following error.
Traceback (most recent call last):
File "hw1.py", line 5, in <module>
from sklearn import svm
ImportError: No module named sklearn
由于某种原因,即使已安装sklearn,也找不到sklearn,并且它在TMUX会话之外也可以正常工作.这是我的进口声明.
For some reason, it can't find sklearn even though it is installed and it works fine outside the TMUX session. Here are my import statements.
import numpy
import scipy.io
from sklearn import svm
from random import sample
为什么在TMUX中找不到模块,我该如何解决?
Why can't it find the module while in TMUX and how do I fix this?
推荐答案
我在OS X上遇到了同样的问题.当在非默认anaconda环境中调用tmux时,似乎PATH变量变得混乱.如果我在调用source activate
之前在新终端中运行tmux,然后在tmux中激活我想要的环境,那么一切都会按预期进行.不幸的是,使用这种解决方法时,我必须记住在tmux中打开的每个窗格中都调用source activate
,所以这不是一个理想的解决方案.
I ran into the same problem on OS X. It seems that the PATH variable gets messed up when you call tmux while in a non-default anaconda environment.If I run tmux in a new terminal before calling source activate
and then activate the environment I want while in tmux then things work as expected. Unfortunately with this workaround I have to remember to call source activate
in every pane I open in tmux so it's a less than ideal solution.
这篇关于TMUX会话不会导入Python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!