Ever since the latest macOS update, I've been using zsh as the default shell. However, all my PATH variables are set up in ~/.bash_profile.
~/.zprofile and ~/.zshenv doesn't exist, and ~/.zshrc has no path variables
My question is: where should I actually put my path variables in the future?
Everything seems to work fine (GO Path, Python, Node paths - none of them are in the zsh profile though..)
Related
I'm running Ubuntu20.04 using WSL2, and I'm rather new to linux. While setting up my environment, I messed up my $PATH, as it no longer includes all of the directories in my windows path. Whenever I open Ubuntu, the terminal spews a bunch of errors of this nature:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
This is one of many errors, one for each component of my windows path. I'm not sure where Windows appends to the linux PATH, so I'm not sure where to look to make the fix.
Edit: Per some of the comments and answers, I do modify the $PATH in my .bashrc, using the code below. Commenting out this code fixes my issue, but I'm not sure what's wrong with this:
function append_to_pathlist
{
# get pathlist into local pathlist (add : at end)
eval "temp_pathlist=\$$1:"
# remove new path from local pathlist if exists
temp_pathlist=${temp_pathlist//"$2:"}
# append new path to front of local pathlist
if [[ "${temp_pathlist}" == ":" ]]; then
temp_pathlist="$2"
else
temp_pathlist="$2:${temp_pathlist}"
fi
# set pathlist to local pathlist (remove : at end)
export $1=${temp_pathlist%":"}
}
# Set the ARCH environment variable
export ARCH="x86_64-ubuntu20_04"
append_to_pathlist PATH "/home/jbrzozo24/.local/bin"
#Add stow pkgs environment variable, and add it to path
export STOW_PKGS_GLOBAL_ROOT="/classes/ece4750/install/stow-pkgs"
export STOW_PKGS_GLOBAL_PREFIX="${STOW_PKGS_GLOBAL_ROOT}/${ARCH}"
append_to_pathlist PATH "${STOW_PKGS_GLOBAL_PREFIX}/bin"
#append_to_pathlist PATH "$/classes/ece4750/install/venv-pkgs/x86_64-ubuntu20_04/python2.7.12/bin"
#PKG CONFIG stu
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/share/pkgconfig"
append_to_pathlist PKG_CONFIG_PATH "${STOW_PKGS_GLOBAL_PREFIX}/lib/pkgconfig"
Windows passes environment variables internally when you start a new WSL process as shown in this article.
Probably some profile script is overwriting the initial PATH variable. This documentation explains how to use Win32 variables inside WSL and the options available:
-bash: export: `Files/Intel/Intel(R)': not a valid identifier
Other possibility part of your path variable containing a non-escaped space or especial characters. You can print your path at the beginning of your ~/.bashrc or ~/.profile to see where is the problem.
When I use vim to update my environmental variables (in ~/.bashrc), PyCharm does not get the updates right away. I have to shut down the program, source ~/.bashrc again, and re-open PyCharm.
Is there any way to have PyCharm source the changes automatically (or without shutting down)?
When any process get created it inherit the environment variables from it's parent process (the O.S. itself in your case). if you change the environment variables at the parent level, the child process is not aware of it.
PyCharm allows you to change the environment variables from the Run\Debug Configuration window.
Run > Edit Configurations > Environment Variables ->
In my case pycharm does not take env variables from bashrc even after restarting
Pycharm maintains it's own version of environment variables and those aren't sourced from the shell.
It seems that if pycharm is executed from a virtualenv or the shell containing said variables, it will load with them, however it is not dynamic.
the answer below has a settings.py script for the virtualenv to update and maintain settings. Whether this completely solves your question or not i'm not sure.
Pycharm: set environment variable for run manage.py Task
I recently discovered a workaround in windows. Close Pycharm, copy the command to run Pycharm directly from the shortcut, and rerun it in a new terminal window: cmd, cmder, etc.
C:\
λ "C:\Program Files\JetBrains\PyCharm 2017.2.1\bin\pycharm64.exe"
I know this is very late, but I encountered this issue as well and found the accepted answer tedious as I had a lot of saved configurations already.
The solution that a co-worker told me is to add the environment variables to ~/.profile instead. I then had to restart my linux machine and pycharm picked up the new values. (for OSX, I only needed to source ~/.profile and restart pycharm completely)
One thing to be aware is that another coworker said that pycharm would look at ~/.bash_profile so if you have that file, then you need the environment variables added there
In case you are using the "sudo python" technique, be aware that it does not by default convey the environment variables.
To correctly pass on the environment variables defined in the PyCharm launch configuration, use the -E switch:
sudo -E /path/to/python/executable "$#"
This is simply how environment variables work. If you change them you have to re-source your .bashrc (or whatever file the environment variables are located in).
from dotenv import load_dotenv
load_dotenv(override=True)
Python-dotenv can interpolate variables using POSIX variable expansion.
With load_dotenv(override=True) or dotenv_values(), the value of a variable is the first of the values defined in the following list:
Value of that variable in the .env file.
Value of that variable in the environment.
Default value, if provided.
Empty string.
With load_dotenv(override=False), the value of a variable is the first of the values defined in the following list:
Value of that variable in the environment
Value of that variable in the .env file.
Default value, if provided.
Empty string.
If I type echo $PATH on my macbook's terminal, this is the output:
/Users/lkloh/Library/Enthought/Canopy_64bit/User/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/lkloh/.rvm/gems/ruby-1.9.3-p448#rails3tutorial2ndEd/bin:/Users/lkloh/.rvm/gems/ruby-1.9.3-p448#global/bin:/Users/lkloh/.rvm/rubies/ruby-1.9.3-p448/bin:/Users/lkloh/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/lkloh/Library/Python/2.7/lib/python/site-packages/pysmo-aimbat-0.1.2/scripts:/usr/local/git/bin:/usr/texbin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
However, if I do vi .bash_profile, this is what I get, and I can't remove the extra links i see in the path.
# Added by Canopy installer on 2014-05-04
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/lkloh/Library/Enthought/Canopy_64bit/User/bin/activate
I did vi .profile, and it does not exist. I also did .bash_rc, and it does not exist. How can I find the file with the sym links I see in my $PATH variable? I want to delete some of them.
Mac OS X setting of environment variables, at the OS desktop level, is quite obscure. There are several useful links in the "Mac OS X" section of this article: https://support.enthought.com/entries/23665767-How-do-I-set-PYTHONPATH-and-other-environment-variables-for-Canopy-
My setup is zsh 5.0.5 in arch linux
I have set the PATH variable as below in .zshenv
typeset -U path
path=(~/bin $path)
DW=$HOME/Downloads
but it didn't work. print $PATH shows only
/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl
.zshenv was read, because I could see DW variable is set. Only PATH variable isn't set. And what I don't understand is, after rename the .zshenv to .zshrc, PATH variable just works as intended.
Need any special treatment setting environment variables in .zshenv?
I just encountered this problem myself, and the real answer is that Zsh on Arch sources /etc/profile – which overwrites and exports PATH – after having sourced ~/.zshenv.
See: https://wiki.archlinux.org/index.php/Zsh#Configuration_files
It seems that when you have macos or some linux distros there is a canonical solution to the problem which involves /etc/paths or /etc/paths.d. You should be letting /usr/libexec/path_helper construct your path for you using configuration files.
This immediately solved the problem in all places for me.
I've got the same problem. The cause was my .zshrc (fresh install of oh-my-zsh) override PATH (ignoring existing value):
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl"
To fix, I comment the line.
I remember after a fresh install of os x, when i did a echo $PATH in the terminal, it responded with a blank line. Now after installing some tools over time, the $PATH variable has /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin value although my .bash_profile is blank. I was wondering where this value is being set?
Plausible candidates would be /etc/profile and /etc/bashrc; there's also /etc/paths and /etc/paths.d to look at. You might also need to look at $HOME/.profile and $HOME/.bashrc. There might be some other places that bash looks too.
As of macOS Catalina, Mac defaults the shell to zsh (Z shell). This type of shell uses .zprofile instead of .bash_profile. To check if you are on bash or zsh, run echo $SHELL. If the result is bin/zsh, you are on zsh. In which case edit your ~/.zprofile for env variables.