When running sublime from desctop it does not see my PERL5LIB environment variable.
When running it from terminal - everithing is OK.
I set my variables in .bashrc and .bash_profile.
import os
>>> os.environ['SHELL']
'/bin/bash'
>>> os.environ['PERL5LIB']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "./os.py", line 676, in __getitem__
KeyError: 'PERL5LIB'
this makes trouble with linting and build system - I can not link and build becase of perl does not see libraries.
How to fix env variable?
Bad news:
The Ubuntu desktop session is no longer affected by .profile.
Additionally bash doesn't parse .profile if either .bash_profile or
.bash_login exists.
You can work around:
Launching desktop application with an environment variable
You can add an environment variable to an application by editing its
.desktop file. For example, to run "digiKam" with the environment
variable APPMENU_DISPLAY_BOTH=1, find the corresponding
digikam.desktop file and add the setting of the variable, via the env
command, to the entry "Exec":
Exec=env APPMENU_DISPLAY_BOTH=1 digikam -caption "%c" %i
or do small script:
#!/bin/bash
source ~/.bashrc
/opt/sublime_text/sublime_text
Related
I installed Anaconda on macOS. It installed successfully, but when I ran the command in terminal it does not recognize the command conda. On my initial search, I found out I have look if the environment variable is set in .bash_profile. As the following picture shows the path is all set, but I can not still run the command.
You are not using bash but zsh as your current shell.
zsh does not source .bash_profile - instead, it sources the .zprofile file for its initialization.
So, just copy the export PATH=... line to the .zprofile file (create it if it does not exist). Logout and login, and it should work.
I am using MACOSX 10.12.3 and Python 3.52
I am running into issues when running pydoc in a bash script in python IDLE.
For example:
myFile = ‘/home/user/afile.py’
import subprocess
subprocess.run([‘pydoc’, ‘-w’, myFile])
Inevitably does not create the html file as would be expected.
On the other hand, when I run pydoc in the terminal
pydoc3 -w /home/user/afile.py
it always creates the wanted html file. But pydoc -w /home/user/afile.py generates an error
This is due to the fact that:
the python /home/user/afile.py contains a few print statements in python3 style. That is: print('blabla') instead of: print 'blabla' as would be the case on python2.
the bash script in IDLE does not load the correct pydoc. I should also mention that running subprocess.run([‘pydoc3’, ‘-w’, myFile]) generates an error, for example:
subprocess.run(['pydoc3', '-w', myFile]) File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 693, in run
with Popen(*popenargs, **kwargs) as process: File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 947, in init
restore_signals, start_new_session) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'pydoc3'
Any one has a way to circumvent this please?
Question 1:
Regarding running the python 3 version of pydoc against python 2 code- That will not work. Pydoc will execute (import) the target module. You would need to use python 2 version of pydoc by modifying your path or using your favorite virtual environment tool.
Question 2:
If you can get a reference to your desired installation of python (by setting the path or activating a virtual environment), then you can handle missing or broken entry points with this syntax:
python -m pydoc -w myfile
You will also need to make sure myfile is in the current directory or on the PYTHONPATH or otherwise importable
This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 5 years ago.
I tried installing Anaconda to get many python packages at once but had some issues with python IDLE where it said No package found so had to manually set the path in ~/.bashrc.
Once I set the path in ~/.bashrc the IMPORT ERROR in python IDLE was solved but I'm unable to use commands on terminal now.
I'm getting this error all the time.
sid#sids-ubuntu:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found
sid#sids-ubuntu:~$ sudo
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found
sid#sids-ubuntu:~$ mkdir aa
Command 'mkdir' is available in '/bin/mkdir'
The command could not be located because '/bin' is not included in the PATH environment variable.
mkdir: command not found
I did export PATH=/usr/bin:/bin to find out my $PATH and content of /etc/environment. It seems both are different.
sid#sids-ubuntu:~$ export PATH=/usr/bin:/bin
sid#sids-ubuntu:~$ echo $PATH
/usr/bin:/bin
sid#sids-ubuntu:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Doesn't Ubuntu look for $PATH in /etc/environment?
If yes, what could be the reason my $PATH is different from /etc/environment? and please help me fix it!
If not, where does Ubuntu look for $PATH? please help me fix it!
Be aware that your /etc/environment is only re-read at reboot.
When you want to change your path, be sure to include the existing part as well. To do that, add $PATH in the new path definition.
export PATH="$PATH:/usr/bin"
Looking at your problems, adding the $PATH in your ~/.bashrc should do the trick. If not, open a new terminal and show us the output of
echo $PATH
When adding some directory to PATH it's good idea not to overwrite previous value, just append desired directory (e.g. $HOME/bin), in your ~/.bashrc add at the end line (and remove any previous tampering with PATH)
export PATH="$PATH:$HOME/bin"
and run:
source ~/.bashrc
(or just open new session of terminal).
PATH is an environment variable, and therefore it is not looked up in any file.
There are several files which are sourced when bash is invoked (see the section named INVOCATION in the bash man page), and while sourcing these files, the environment variable PATH can be set, respectively manipulated. Note that .bashrc is not always processed; please read the bash man-page carefully to understand, which files are included under which condition.
I am sourcing virtualenvwrapper so that I can use virtualenvwrapper functions in a bash script, as in the following simplified example:
Running do_some ve_name branch_name calls:
#! /bin/bash
# some script that takes parameters
source /etc/bash_completion.d/virtualenvwrapper # the magic of sourcing
workon $1 # pick a venv
cd /some/project/path
git checkout $2 # pick a branch
python do_something.py
This works (and I don't mind dropping out of the virtual environment once it ends, in fact I prefer it). However, if I am already in a virtual environment I get the following:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/home/username/.virtualenvs/ve_name/bin/python and that PATH is set properly.
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader
So let's just assume that I will occassionally forget to deactivate my current virtualenv. I tried resolving this as follows:
#! /bin/bash
# some advanced script that takes parameters
deactivate
source /etc/bash_completion.d/virtualenvwrapper # the magic of sourcing
workon $1 # pick a venv
...
But whether or not I am currently in a virtualenv, I get the following error (and it doesn't deactivate if I am accidentally in a virtualenv, which is the problem I want to solve):
/path/to/scripts/do_some: line 4: deactivate: command not found
So, how can I protect against already being in a virtualenv before sourcing virtualenvwrapper commands?
You might also try using the VIRTUAL_ENV environment variable as well. I found this to be a clearer solution after viewing this, so I thought I'd leave a note in case this is reaching others searching for similar solutions.
E.g.,
if [ ${VIRTUAL_ENV} ]
then
# do some stuff
fi
Here's the relevant portion of the deactivate function in the activate script:
# (inside deactivate function)
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
Here's how that gets set when you originally source the file:
# (runs when you source the activate file)
VIRTUAL_ENV="/path/to/venv/dir"
export VIRTUAL_ENV
This may not solve the original question (didn't test), but it's helpful for a large subset of cases where you just need to know if you're in a virtualenv or not.
If I understand it correct, the function workon is defined by the virtualenvwrapper. You could check if the function is defined before attempting to source the wrapper.
Replace your source command with the following:
[[ $(type -t workon) == "function" ]] || source /etc/bash_completion.d/virtualenvwrapper
I get an error when I try to create a new virtualenv using virtualenvwrapper. Here's the command I'm trying:
mkvirtualenv -a . -i Flask ~/.virtualenvs/dcc-admin/
Here's the output:
New python executable in /Users/raddevon/.virtualenvs/dcc-admin/bin/python
Installing setuptools......
Complete output from command /Users/raddevon/.vir...dcc-admin/bin/python -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" /Library/Python/2.7/...ols-0.6c11-py2.7.egg:
Processing setuptools-0.6c11-py2.7.egg
Removing /Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg
error: /Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg: Permission denied
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.9.1', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 979, in main
no_pip=options.no_pip)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1091, in create_environment
search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 611, in install_setuptools
search_dirs=search_dirs, never_download=never_download)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 583, in _install_req
cwd=cwd)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1057, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/raddevon/.vir...dcc-admin/bin/python -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" /Library/Python/2.7/...ols-0.6c11-py2.7.egg failed with error code 1
I thought I could get around this with sudo, but that gives me sudo: mkvirtualenv: command not found.
I've checked my permissions on the file causing the error, and my user appears to have read and write permissions.
I'm not sure where to go from here. mkvirtualenv should be able to delete that file since I have the delete permission for it. Alternately, sudo should be able to run mkvirtualenv. Someone please tell me where I'm going wrong.
Update: I figured out part of this problem. virtualenvwrapper was trying to run the Python commands through a different install of the Python interpreter than the one I wanted. I used the -p switch to specify the correct interpreter, and that worked.
I read up on this, and, apparently, it should be using the same interpreter that would be the default in my shell, but this is not the case. The interpreter used as the default by the shell is /usr/local/bin/python but virtualenvwrapper is trying to run through /Library/Python/... I'm still unsure why this is the case. /usr/local/bin is the last python path defined in my .zshrc.
I currently found a workaround
virtualenv env -p /usr/local/bin/python