I am trying to learn how to program using Django, but I am stuck dealing with some problems related to the use of virtualenv and virtualenvwrapper.
I am using a Mac with the following OSX OS X El Capitan 10.11.3 with Python 2.7.10 as default.
I have just recently downloaded Python 3.5 and also virtualenv and virtualenvwrapper using the following commands in the terminal:
pip install virtualenv
pip install virtualenvwrapper
This seemed to work smoothly, and so I followed the installation guide found at Virtualenvwrapper Installation Guide in order to correctly modify the .bash_profile so that the virtualenvwrapper is loaded correctly.
However, there are some of the guidelines I do not fully understand and thus I am not able to successfully set up the virtualenvwrapper.
The following lines are said to be added to the shell startup file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
But when I installed the virtualenvwrapper, the virtualenvwrapper.sh was stored in the following path: Library/Frameworks/Python.framework/Versions/3.5/bin/
In other words, there is no file called virtualenvwrapper.sh at /usr/local/bin/.
My shell startup file currently looks like this:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
When I now try to write the following code in terminal:
source ~/.bash_profile
the following outputs:
-bash: /usr/local/bin/virtualenvwrapper.sh: No such file or directory
I have also tried to change the path of the source in the .bash_profile to the following:
source Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
which is where the virtualenvwrapper.sh file is located. This however, gives the following output:
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
Any suggestions as to how I should fix this? I am sorry for the length of the question, but I wanted to explain the problem thoroughly.
I would be really thankful for any answers :)
virtualenvwrapper.sh should be in your path somewhere. The simplest solution is tp change the source statement to read
source `which virtualenvwrapper.sh`
Note the back-ticks around the which virtualenvwrapper.sh part of the command.
That will find it in the path, wherever it actually lives. And yes, on a mac, it is often in Library/Frameworks/ etc. But that should be on your path because part of the install for python will put it there.
Related
I'm setting up a new machine (OSX 10.12.6) and trying to get my python environment setup. I have installed both 2 and 3 with brew. The solutions described in other questions don't seem to help.
.zshrc looks like this:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/projects
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
source /usr/local/bin/virtualenvwrapper.sh
Error I'm getting when I open a new shell:
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
The weird thing is that everything works fine - I can use mkvirtualenv just fine. But I don't want the error message and I don't get what is going on with my path? Please help!
I installed virtualenv and wrapper with pip and pip3
pip freeze:
pbr==3.1.1
six==1.10.0
stevedore==1.26.0
virtualenv==15.1.0
virtualenv-clone==0.2.6
virtualenvwrapper==4.8.1
$PATH:
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I'm trying to install virtualenv and virtualenvwrapper so that I can do some django work.
I'm not exactly sure where the issue is stemming from. I currently have installed Jupyter Notebook and installed a lot of python files though it (python 3+ I believe), so when I did pip install virtualevnwrapper, the location of the shell file was in C:/Users/'Andy Renz'/Anaconda3/Scripts/virtualenvwrapper.sh. I account for this in changing by .bashrc file, by including:
export WORKON_HOME=$HOME/.virtualenvs
source C:/Users/'Andy Renz'/Anaconda3/Scripts/virtualenvwrapper.sh
When I run source ~/.bashrc in my shell, I get the following:
bash: /usr/bin/python: No such file or directory
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could no import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and the PATH is
set properly.
I think this means python isn't where it is supposed to be. Virtualenv references python 2+ I believe which leads me to believe my python 2 is somewhere odd. I do have it, not downloaded from Jupyter. How do I account for this and proceed forward?
The issue is you're trying to install the default virtualenvwrapper (for Linux) on a Windows machine. That's why it's trying to get Python from /usr/bin/python, a directory that does not exist in Windows.
Try virtualenvwrapper-win from https://pypi.python.org/pypi/virtualenvwrapper-win
Python is somehow either not installed or installed at different path maybe /usr/local/bin. Use which python or whereis python to check if python is indeed installed and path of installation. Then you can create a softlink to the python executable in your /usr/bin directory.
I am facing following 2 issues:
python command is not using the virtualenvwrapper python.
After activating my virtual environment if I type python then the code still uses the native python libraries. I can easily install libraries etc with pip to my virtual environment but I cannot run any command using python.
e.g. if I execute $ ./manage.py runserverthen it is fine and I can run a django server
but if I try $ python manage.py runserver
or even just
$ python
then it uses the native python libraries and that should not happen
This is while using iterm or terminal in osx. I have never faced this problem in any linux based os
While using any os (linux based or osx), the workon command doesn't work inside any shell script, while it works normally in a terminal
os: osx
sounds like Python might be using the packages in site-packages, which means you should use the --no-site-packages flag when creating your virtualenv (although it seems like this is the default in the current version of virtualenv).
In order to access the virtualenvwrapper functions from a shell script, you will first need to source it: $ source /usr/local/bin/virtualenvwrapper.sh (the path might be different in your case).
You could try install virtualenv and virtualenvwrapper from pip3.
pip3 install virtualenv virtualenvwrapper
And then find where virtualenvwrapper.sh file is:
find / -name 'virualenvwrapper.sh'
I have mine in /usr/local/bin/virtualenvwrapper.sh. But it seems that you have it in some different directory. So you must change below config to fit your needs.
And then in your .bashrc or .zshrc:
# Python3 virtualenv/venvwrapper
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3' # This needs to be placed before the virtualenvwrapper command
export PROJECT_HOME=$HOME/Projects
source /usr/local/bin/virtualenvwrapper.sh # your path to virtualenvwrapper.sh
Let me know if it works :)
I'm trying to uninstall Anaconda (the why doesn't matter). Using this article: Python Anaconda - How to Safely Uninstall, but it appears I'm having different issues.
I used rm -rf ~/anaconda, entered python3 in my terminal and get: -bash: /Users/myuser/anaconda/bin/python3: No such file or directory
It looks like my python path is incorrect. Looking at this comment: export https://stackoverflow.com/a/37377981/994558, I used nano ~/.bashrc but that files doesn't exist.
I'm confused because which python gives me: /usr/bin/python
Any help?
I'm trying to use python3's built in pip3 package manager to install virtualenv and Django so I can learn more about python but after installing them both and trying to use virtualenv, the terminal throws:
zsh: command not found: virtualenv
But I can see that the virtualenv is installed on:
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
I also tried creating a symlink to virtualenv.py to /usr/local/bin but when I try to run virtualenv in the terminal its giving me zsh: permission denied: virtualenv
I'm on a OS X machine. I installed Python 3 along side Python 2.7, which the machine came with.
Has anyone experience this problem before? I'd appreciate any advice/solution you guys could give. Thanks in advance!
You might use Bash before using Zsh. And the python had been updated when you used Zsh.
I got the same problem. Zsh could not find python3 packages. But when I changed the shell to Bash, the python3 packages could be found.
I solved the problem in the way as follows:
Open the terminal and input the command:
nano .bash_profile
Copy the settings in the .bash_profile:
# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Input the command:
nano .zshrc
Paste the code to the end of the .zshrc.
(.bash_profile is the settings file of Bash, .zshrc is the settings file of Zsh)
Restart the terminal.
Try to find the python3 packages, such as virtualenv:
which virtualenv
You may find the PATH of virtualenv.