Issues setting up Virtualenv and Virtualenvwrapper - python

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.

Related

virtualenvwrapper not installing correctly?

I am trying to use a Python virtual environment for the first time while trying to learn Django. I am using the instructions here. As I am using git bash on Windows, I am following the setup instructions for Windows.
I installed virtualenvwrapper using
pip3 install virtualenvwrapper-win
Now the command mkvirtualenv gets me bash: mkvirtualenv: command not found
I tried the solutions here to no avail.
pip3 list shows that the package is, in fact, installed, but there is no virtualenvwrapper (or virtualenv) .sh files in the site-packages directory, and the only related file I can find is virtualenvwrapper_win-1.2.5-py3.6.egg-info in an AppData/Roaming directory.
Any suggestions? Thanks.
I had the same problem and tried uninstalling virtualenvwrapper-win, just to see the list of files that would be removed. I saw that the mkvirtualenv was located in C:\Python\Python37\Scripts.
I noticed I was using the 64bit version of python (C:\Python\Python37\) alongside the 32bit one (C:\Python\Python37-32\), both folders being in the PATH of my system's properties. I removed the 32bit version's directories from the PATH and this seemed to work.
PS: I also noticed that running the commands from the MINGW terminal requires them to also have the .bat extension added:

issues with python virtual environment

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 :)

Installing and using virtualenvwrapper

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.

Pip "install" Installs in Jython instead of python

I am trying to install "XLRD" library for python using PIP install, the library is installed successfully, after execution i tried to import the same but i get the error that no modules have been installed.
After some research i found that everything is getting installed in the C:jython/site-packages directory instead of C:/python27.
My pythonpath is set to C:/python27 , I checked.
What could be the issue? How do i instruct PIP to install modules in python directory.
On your terminal/command prompt navigate to the Python home directory of the version for which you need to install the module. Then navigate into the scripts folder and run the pip command. Like below
cd C:/python27/Scripts
pip install XLRD
You basically need to point to the pip script for which you need to run this command. If thats for the pip script inside the python27, you need to navigate there or do like below as well
C:/python27/Scripts/pip install XLRD
If you have both the python27 & jython home directory & script paths in your 'PATH' environment variables, the path that was declared first takes precedence. To rearrange precedence, you would have to rearrange the order of the path declaration.

Installing python packages with no installation directory acces and no pip/easy_install/virtual_env

At work we have python installed, but no additional modules. I want to import some scipy modules but I have no access to the python directory for installation.
Similar questions have been asked on StackOverflow, but the answers always assumed easy install, pip or virtualenv were installed. At my workplace, none of these packages are installed. It's just the plain python installation and nothing else.
Is there still an option for me for installing modules in my local folder and calling them from python? If so, how do I go about it?
Not exactly installing modules on your local folder, but a solution nonetheless:
I used to work for a company that used windows and didn't have admin access, so I ended up using Portable python.
It seems portable python is no longer mantained, but you can see some other portable python solutions on their site, most of which you can run straight from your usb.
You can download pip from here http://pip.readthedocs.org/en/stable/installing/ and install it without root privileges by typing:
python get-pip.py --user
This will install to directory with prefix $HOME/.local so the pip executable will be in the directory $HOME/.local/bin/pip, for your convenience you can add this directory to $PATH by adding to end of .bashrc file this string
export PATH=$HOME/.local/bin/:$PATH
After this you can install any packages by typing
pip install package --user
Or you can alternatively compile the python distribution from source code and install to your home directory to directory $HOME/.local or $HOME/opt or any subfolder of $HOME you prefer, let's call this path $PREFIX. For doing this you have to download python source code from official site, unpack it and then run
./configure --prefix=$PREFIX --enable-shared
make install
And then add python binary to $PATH, python libraries to $LD_LIBRARY_PATH, by adding to the end of $HOME/.bashrc file whit strings
export PATH=$PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PREFIX/lib
and when after restarting bash you can also run
python get-pip.py
and pip and will be installed automatically to your $PREFIX directory. And all other packages those you will install with pip will be automatically installed also to $PREFIX directory. This way is more involved, but it allows you to have the last version of python.

Categories