I encountered and solved this problem earlier this day and now I run into something similar but in another context.
When I fire up python (2.7) in my mac Terminal (Mac OS Lion) and do
import oursql
everything is fine.
When I do the same within a python script in the Aptana IDE I get the following error.
Traceback (most recent call last):
File "/Users/salah/Documents/Aptana Studio 3 Workspace/pubmap/src/scripts/parse_all_dblp_authors.py", line 10, in <module>
import oursql
ImportError: dlopen(/Library/Python/2.7/site-packages/oursql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/oursql.so
Reason: image not found
This is the same error as in the problem above which I used to solve by adding
PATH=${PATH}:/usr/local/mysql/bin
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"
to .bashrc and
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
to .bash_profile.
Why does this have no effect on Aptana? By the way Aptana is a derivate of eclipse so everything relevant to eclipse should be relevant to Aptana, too - at least I think so...
Edit:
A suggestion by Peter in his answer below brought me a possible solution. Just set the path right into the interpreter Options of Python in Aptana/Eclipse/Pydev. See the following Screenshot:
It's been a while since I used Pydev, but the Pydev docs on configuring the interpreter are probably worth a look.
Python IDEs usually let you configure the environment python is run in when you run from the IDE.
Also, having .bashrc change your $PATH will only change the environment variable for bash sessions. Unless you run Aptana from bash changing your .bashrc won't change the envirnment variables Aptana gets. See setting-environment-variables-in-os-x.
Aptana Studio does not read .bashrc. However it does include other files in the following order:
if [ -f /etc/profile ] ; then . /etc/profile; fi
if [ -f ~/.bash_profile ] ; then . ~/.bash_profile;
elif [ -f ~/.bash_login ] ; then . ~/.bash_login;
elif [ -f ~/.profile ] ; then . ~/.profile;
[[ -f ~/.aptanarc ]] && . ~/.aptanarc
Cheers,
Max
Related
I would like to add my site-packages directory to the PYTHONPATH variable, so I can import modules which are stored there to use them in scripts in interpreter. My default shell is zsh, and the OS is macOS Monterey, version 12.6.
I have tried to open the ~/.zprofile in nano editor from my terminal, adding the path I need, and restarting my terminal, but it did not help to solve the issue. After restarting the terminal, I tried to run following commands:
narynaa#Narynas-MacBook-Pro ~ % echo ~/.z.profile
/Users/narynaa/.z.profile
narynaa#Narynas-MacBook-Pro ~ % cat ~/.zprofile
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
export PYTHONPATH="/opt/homebrew/lib/python3.10/site-packages"
The path I need is stored inside the ~/.zprofile file now, but the problem is not solved.
Thank you for your help!
I have latest GVim (v8.2) 64-bit and Miniconda Python 3.8.5 64-bit installed on Windows 10. I am working in the virtual environment da38 and included the following two lines in my $HOME\_vimrc file to point to the correct python interpreter and libraries for this environment:
set pythonthreehome=$HOME\miniconda3\envs\da38
set pythonthreedll=$HOME\miniconda3\envs\da38\python38.dll
Both :echo has('python3') and :echo has('python3_dynamic') return 1. I have installed Vim plugin dense-analysis/ale for python linting, and installed flake8 and black packages in da38 using conda install flake8 black. And I added the following lines in $HOME\_vimrc to configure this plugin:
let g:ale_linters = {'python': ['flake8']}
let g:ale_fixers = {'*': [], 'python': ['black']}
let g:ale_fix_on_save = 1
But the plugin does not show any error on a python file that has many by design: running flake8 test.py on command prompt returns a lot of errors. :ALEInfo repeats these two lines several times:
(executable check - failure) flake8
(finished - exit code 1) 'cmd /s/c "cd /d "C:\Users\Admin\Desktop" && black - < C:\Users\Admin\AppData\Local\Temp\VIBA694.tmp\test.py"'
I am wondering if somehow the correct python path is not being passed to Vim, but cannot figure out what else to do. Any help is much appreciated.
Thanks
UPDATE:
I think I narrowed down the problem. Linter plugin fails when I open test.py with vim from the desktop icon, but works if I first activate the virtual environment with conda activate da38 and then start vim on command prompt. I guess the desktop vim does not see the virtual environment, where the two packages flake8 and black are installed. So I believe the problem is how to add the appropriate python environment to the desktop vim. I should add the vim-conda plugin did not help.
UPDATE #2:
I managed to get vim-conda plugin working with gvim, and now the linter plugin works as expected.
UPDATE #3:
One can avoid using a plugin and instead hard-code the environment path in _vimrc (for windows):
let venv = 'da38'
let mypath = 'C:\Users\Admin\miniconda3\envs\' . venv . ';'
\ . 'C:\Users\Admin\miniconda3\envs\' . venv . '\Scripts;'
\ . 'C:\Users\Admin\miniconda3\envs\' . venv . '\Library\bin;'
let $PATH = mypath . $PATH
This code sticks the env path in front of default $PATH.
I have installed virtualenv and the virtualwrapper via apt-get, I got to a point where I created a virtual enviroment but however later on during that same day when I used the workon command it was not found. I further on went and inspected my home directory and .virtualenvs dir and the virtualenv I created earlier were still there.
Solving this problem took two steps:
Add this to your .bashrc / .bash_profile / .zshrc:
# load virtualenvwrapper for python (after custom PATHs)
venvwrap="virtualenvwrapper.sh"
/usr/bin/which -s $venvwrap
if [ $? -eq 0 ]; then
venvwrap=`/usr/bin/which $venvwrap`
source $venvwrap
fi
Then use:
source .bash_profile
# or .bashrc / .zshrc
to reflect the changes.
Additionally, if the terminal still sometimes cant find workon, use source .bash_profile to reset and find it again.
type source .profile in home directory from terminal.
Read the readme in the top of which virtualenvwrapper.sh
You need to source it inside bashrc
open ~/.profile
cd ~
nano .profile
add at the end
#virtualenvwrapper setup
export WORKON_HOME=$HOME/envs
export PROJECT_HOME=$HOME/dev
source /usr/local/bin/virtualenvwrapper.sh
to load your .profile file you just edited:
$ . .profile
I ran in to this problem too and I simply needed to logout and log back in.
This read in the changes which the debian package manager made to my system at /etc/bash_completion.d/virtualenvwrapper
I am following this tutorial on how to set up a virtual environment in Python3.6 using the windows command prompt. I had no problem generating the necessary file by running this:
python3 -m venv venv-test
The tutorial then advises to activate the virtual environment by running this code:
venv-test/Scripts/activate
But when I do this , I get the error...
File "venv-test/Scripts/activate", line 4
deactivate () {
^ SyntaxError: invalid syntax
I opened the generated 'activate' file and this seems to be the part that's causing the problem but I'm not sure how to correct it.
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
Thanks in advance!
Try this:
source venv-test/bin/activate
It worked here. Make sure you're in the folder that contains your venv, otherwise just mention its full path.
I haven't got access to a windows machine at the moment but if I remember correctly you need to run activate.bat and I think you need the full path.
So something like:
C://code/project/venv-test/Scripts/activate.bat
On Python 3.8 just go to the folder containing the virtual environment and type
source venv-test\scripts\activate
not sure the reason why running
venv-test/Scripts/activate
doesn't work but if you go into the directory venv-test/Scripts and THEN type activate it works fine.
change directory to scripts directory as follows:
cd venv-test/Scripts
and run the activate file by typing
activate
at the prompt
you have to run source venv-test/bin/activate not venv-test/Scripts/activate
I had the same problem before, try typing :
venv-test/Scripts/activate.bat,
it worked for me
I have an access to a Dreamhost subdomain on which I'm trying to run a Django REST app. The server runs on Ubuntu 12.04.5 LTS. Something went wrong in my virtual environment, so I'm trying to follow Dreamhost's instructions to install Python again. I get stuck at step 4:
. ~/.bash_profile
The command doesn't return, and I have to interrupt it to get back. Here's my .bashrc:
# ~/.bashrc: executed by bash(1) for non-login shells.
export NVM_DIR="/home/julius/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
source .bash_profile
and here's my .bash_profile:
# ~/.bash_profile: executed by bash(1) for login shells.
umask 002
PS1='[\h]$ '
. $HOME/.bashrc
export PATH=$HOME/opt/python-3.5.1/bin:$PATH
What am I doing wrong?
It never returns because it can never complete. Your .bash_profile sources your .bashrc, which in turns sources (.s) your .bash_profile, which sources your .bashrc, which ...
The bash source command (or ., which is just another name for the same thing) is not like a require or import statement that only happens once. It is an runtime command that executes the sourced file every time it's encountered.
You have infinite recursion when loading .bashrc or .bash_profile since they both source each other. You should probably remove the call to . $HOME/.bashrc to prevent this.