Giter VIP home page Giter VIP logo

Comments (7)

seagle0128 avatar seagle0128 commented on May 14, 2024 2

这是因为你的GUI环境和terminal环境的环境变量不同导致的。你可以用M-x getenv RET PATH RET来查看。另外,你可以在GUI和Terminal下分别执行以下命令获取Python版本:M-! python --version

GUI环境下,建议用exec-path-from-shell导入Terminal下的PATH,这样就保持一致了。

from .emacs.d.

seagle0128 avatar seagle0128 commented on May 14, 2024 1

看起来你是直接用的Centaur Emacs。 目前个人使用zsh (参考配置https://github.com/seagle0128/dotfiles ),为了加快启动速度,去掉了参数"-i"(--interactive), (setq exec-path-from-shell-arguments '("-l")) 。这段告警我默认屏蔽掉了。

exec-path-from-shell中有这样一段message:

"You appear to be setting environment variables %S in your .bashrc or .zshrc: those files are only read by interactive shells, so you should instead set environment variables in startup files like .profile, .bash_profile or .zshenv. Refer to your shell's man page for more info. Customize exec-path-from-shell-arguments' to remove \"-i\" when done, or disable exec-path-from-shell-check-startup-files' to disable this message."

如果你不怕启动慢,可以设置参数为(setq exec-path-from-shell-arguments '("-l" “-i”))。个人更建议把环境变量之类的放到.profile, .bash_profile 或者 .zshenv。这算是一个比较复杂的问题了,你很细心注意到了。我会先加到FAQ里,方便其他人查阅。

谢谢你的详细反馈!

from .emacs.d.

seagle0128 avatar seagle0128 commented on May 14, 2024 1

你可以用C-h f exec-path-from-shell-copy-env RET 查看帮助。这个函数必须带参数(环境变量的名字)
(exec-path-from-shell-copy-env NAME)

所以,如果你使用应该像这样:M-x exec-path-from-shell-copy-env RET PATH RET

这个包的原理就是解析shell启动配置,将需要的环境变量通过exec-path-from-shell-copy-env 拷贝到Emacs内部。

from .emacs.d.

lartpang avatar lartpang commented on May 14, 2024

您好。

看了您的回复,确实,在图标启动的emacs中 getenv path中并未包含添加在 .bashrc 的环境变量。

我对于elisp不熟,我发现将我需要的path放到~/.profile中,也可以解决这个问题。

主要的问题在下面,多谢解答!

但是我又看到,您的配置中使用了插件 exec-path-from-shell

image

我查了下,这个插件就是用来除了这个问题的。

This library works solves this problem by copying important environment variables from the user's shell: it works by asking your shell to print out the variables of interest, then copying them into the Emacs environment.

问题:但是,为什么我的还会出现这样的问题呢?


而且我发现了这个插件的一条指令:

image

执行后发现有这样的结果:

image

问题:请问这个问题又是出在哪里?


这里是我的 .bashrc(我是用的是tilix终端模拟器,并未作为登录终端,默认使用的是bash)

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

# cuda
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# added by Anaconda3 installer3
export PATH="/home/lart/anaconda3/bin:$PATH"

#my alias
alias jn='jupyter notebook'
export BROWSER=google-chrome-stable

#tilix
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
    source /etc/profile.d/vte.sh
fi

from .emacs.d.

lartpang avatar lartpang commented on May 14, 2024

首先感谢您的积极回复,确实,加上了 "-i" 参数会使得emacs可以读取到.bashrc的PATH,但是我对于这个指令:

img

的结果很疑惑。

问题:是不可以像我这样使用么?或者说是有其他的原因?

我的流程:

  1. M-x exec-path-from-shell-copy-env RET
  2. RET
  3. 得到了下面的错误

image

from .emacs.d.

lartpang avatar lartpang commented on May 14, 2024

非常感谢您的耐心解释,理解了。

from .emacs.d.

seagle0128 avatar seagle0128 commented on May 14, 2024

不客气。Enjoy 😄

from .emacs.d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.