Problems installing virtualenvwrapper in Cygwin - python-3.x

I'm trying to get started with a book called "TDD with Python", OS W10. As part of the setup it wants you to install virtualenvwrapper. The recommendation is to use GitBash in Windows... but I've been using Cygwin for quite a bit and didn't like GitBash when I looked at it some time ago.
Python version is 3.6. I installed virtualenvwrapper by going
pip install virtualenvwrapper
This seemed to work OK.
Trying to add the relevant setup line to my .bashrc did not go so well:
echo "source virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
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.
At least this proves that virtualenvwrapper.sh is being run...
In fact there is no such directory as /usr/bin ... so I added a preceding line in .bashrc pointing to what I hoped might be what it might be wanting to see for this VIRTUALENVWRAPPER_PYTHON environment variable (do we call them that in Linux?).
VIRTUALENVWRAPPER_PYTHON=/cygdrive/d/apps/Python/Python36/Lib/site-packages/virtualenvwrapper
Now I get
bash:
/cygdrive/d/apps/Python/Python36/Lib/site-packages/virtualenvwrapper:
Is a directory 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=/cygdrive/d/apps/Python/Python36/Lib/site-packages/virtualenvwrapper
and that PATH is set properly.
Main question: what is VIRTUALENVWRAPPER_PYTHON meant to point at? An executable file? Any clues to help me recognise the desired target would be much appreciated!
POST-ANSWER ENLIGHTENMENT Just in case anyone stumbles this way, just to let you know: after phd gave me the answer to this I found other problems.
Eventually I managed to install virtualenvwrapper by doing this:
pip uninstall virtualenvwrapper
... use the latest Cygwin setup .exe to install pip3. Note the 3!
then go
pip3 install virtualenvwrapper
echo "source virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
... success! but quickly followed by another puzzle: see here.

VIRTUALENVWRAPPER_PYTHON should point to python binary: /usr/bin/python, e.g.

Related

Installed python packages will stay in site packages 3.10?

Specs:
Macbook Air M1 Ventura
Visual Studio Code Version: 1.75.0
which brew
/opt/homebrew/bin/brew
which pip3
/opt/homebrew/bin/pip3
(which is a link to:
/opt/homebrew/Cellar/python#3.10/3.10.10/bin/pip3 )
tl;dr:
I don't have python installed through brew anymore, but only as pyenv (and only version 3.11.1) - my Mac native version is 3.9.6)
YET whenever I install something through the activated virtualenv it will re-create a folder in /opt/homebrew/lib/python3.10/site-packages.
I don't understand why it keeps fussing about python3.10 so much and how I can get packages installed to any other environment. It seems my pc is only the folder mentioned above.
What I tried:
Since a module (twarc-csv as part of the twarc2 package) didn't work anymore (when trying to run, it says Error: No such command 'csv'.; which twarc-csv in terminal also didn't find it), I started looking into my python environments. the developer of the package suggested it was related to versionings and recommend using pyenv.
I have to say that before installing pyenv I upgraded twarc (to be sure) in terminal with brew install twarc --upgrade (as I already figured my pip3 path and my python path didn't align see python mess) which automatically fetched python3.11.1 as a dependency for twarc for some reason. As a result besides the Mac native python version I now had python 3.11 and 3.10 installed.
Even when I explicitly ran 3.11 though (e.g. python3.11 -m pip install twarc --upgrade twarc-csv), packages would still be installed to this folder /opt/homebrew/lib/python3.10/site-packages though. So something was off.
I decided to go with the suggestion from said developer and try pyenv. I strictly stuck to this guide: clean pyenv environment and VSCode seemed to find my pyenv virtualenv installed python version. However even though which pip3 led to the virtual shims path, the packages were still installed to /opt/homebrew/lib/python3.10/site-packages
Ok, if I wouldn't really need this package to run, I would already have given up, but since things are the way they are... I decided to delete pyenv and reinstall python3 through brew.
As you might have figured by now, the cycle started from anew. I wanted to check into why this path is so dear to my setup /opt/homebrew/lib/python3.10/site-packages Visual Studio would also still indicate that python 3.10.10 is global, so I checked
import sys
import pprint
pprint.pprint(sys.path)
I checked this for 3.11 and 3.10 environment in VSCode
the one for 3.10 being
'/opt/homebrew/Cellar/python#3.10/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python310.zip',
'/opt/homebrew/Cellar/python#3.10/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10',
'/opt/homebrew/Cellar/python#3.10/3.10.10/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload',
'/opt/homebrew/lib/python3.10/site-packages']
the one for 3.11 being
'/opt/homebrew/Cellar/python#3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python311.zip',
'/opt/homebrew/Cellar/python#3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11',
'/opt/homebrew/Cellar/python#3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload',
'/opt/homebrew/lib/python3.11/site-packages']
plus my desktop, so this seems to be fine. Nevertheless even if I use interpreter 3.11 in VSCode it will still look for packages in python3.10 and not install them to 3.11
Now I checked $PATH and see what it says, and it still refers to pyenv it seems:
$PATH
zsh: no such file or directory: /Users/myusername/.pyenv/shims:/Users/myusername/.pyenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/go/bin:/Library/Apple/usr/bin
So how do I clean that up?
Also, how do I get things to run correctly? I do not understand that affection to the sitepackages 3.10 at all.
Update:
I am wondering whether my zprofile, zshrc or bashrc or bash_profile files have to do with it.
That's how they look:
(bashrc is empty)
bash_profile
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
zprofile
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
zshrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi

Invoking pip packages from the CLI?

I installed a pip package (Spyder) on Debian using pip3 install spyder=5.0.5. However, running spyder from the command line interface says that it's not found. I hacked a solution by adding an alias in my .bashrc that points to some obscure start.py file that launches Spyder.
I'm sure there must be a more orthodox way of invoking Spyder, presumably by editing the $PATH, but I'm not sure how.
As #phd said in the comments, I had to edit my $PATH to point to directory where pip3 installs its packages. Namely, I had to run export PATH="$HOME/.local/bin:$PATH" and that fixed the problem.

pip in path but command not found

I'm running a fresh installed OctoPi image (0.18.0). I added pip to my PATH in .bashrc file and sourced it but when I try to run pip I'm getting -bash: pip: command not found error.
When I run /home/pi/oprint/bin/pip, pip is working properly.
My path:
pi#octopi:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/oprint/bin/pip:
You added the full path of the executable to the path, but you're only supposed to add the directory of the executable. Every exectuable of said directory is then directly available without the directory prefix.
In other words .. instead of /home/pi/oprint/bin/pip you should add /home/pi/oprint/bin/ to the path.
I always recommend using the Python executable to locate the pip executable for you. This way, you know the right version of pip is being used to install packages that are compliant with your Python version.
$ python -m pip install <the_package_you_want>
It is really easy to end up with mismatched versions otherwise!

Learning OSX terminal in depth - How to solve the "usr/bin/python: No module named..." error

I'm learning my way around console again and would love to understand error messages in depth. Using Mac OSX and ZSH.
Here is the first one to crack:
Last login: Thu Mar 29 16:00:27 on ttys000
/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.
This obviously means that one of the Pythons installed on my Mac could not load one of the packages (virtualenvwrapper). To orient myself I tried a couple of things to get the "stats" about my system.
Here is what I tried:
~ ❯ which python
/usr/bin/python
First Python (system one, the one that comes with Apple OSX)
~ ❯ which python3
/usr/local/bin/python3
Second Python (Python3, installed by me via Homebrew package manager)
~ ❯ which pip
/usr/local/bin/pip
~ ❯ which pip3
/usr/local/bin/pip3
Same as with pythons, two PIPs - first one is the one that "works with" the system Python installation, and the second one that comes with brewed Python3.
~ ❯ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin
seems that my $PATH variable is set properly in the ~/.zshrc (is this the proper file?)
Potential culprit:
~ ❯ pip install virtualenvwrapper
Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.6/site-packages
~ ❯ pip3 install virtualenvwrapper
Requirement already satisfied: virtualenvwrapper in /usr/local/lib/python3.6/site-packages
Is this the problem? Both PIPs are saying that I already have the missing package installed, but in the same location (in the brewed Python3). Do I need to re-link something?
EDIT:
I tried one more thing:
printenv | less
returns this:
WORKON_HOME=/users/edchigliak/documents/projects/.virtualenvs
PROJECT_HOME=/users/edchigliak/documents/projects
VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
VIRTUALENVWRAPPER_WORKON_CD=1
VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
VIRTUALENVWRAPPER_HOOK_DIR=/users/edchigliak/documents/projects/.virtualenvs
Last line might be the suspect. Seems that the ZSH cannot source thie "... _HOOK_DIR" I just don't know how to fix this.
This solved my issue - I added the following line to my shell configuration file (in my case ~/.zshrc):
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
By doing so I obviously told virtualenvwrapper where to look for "proper" python (python 3 instead of the system-wide installed python 2).

Install virtualenv and virtualenvwrapper on MacOS

How to install and configure virtualenv and virtualenvwrapper for Python on MacOS?
To install virtualenv and virtualenvwrapper for repetitive use you need a correctly configured Python (this example uses Python 3.x but process is identical for Python 2.x).
Although you can get python installer from Python website I strongly advice against it. The most convenient and future-proof method to install Python on MacOS is brew.
Main difference between installer from Python website and brew is that installer puts python packages to:
/Library/Frameworks/Python.framework/Versions/3.x
Brew on the other hand installs Python, Pip & Setuptools and puts everything to:
/usr/local/bin/python3.x/site-packages
And though it may not make any difference to you now – it will later on.
Configuration steps
Install brew
Check out brew installation page or simply run this in your terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Python
To install python with brew run:
brew install python3
Now your system needs to know where to look for freshly installed Python packages. Add this line to youre ~/.zshrc (or ~/.bash_profile if you're using bash):
export PATH=/usr/local/share/python:$PATH
Restart your terminal.
To make sure you've done everything correctly run which python3 and in return you should receive /usr/local/bin/python.
Install virtualenv & virtualenvwrapper
Now it's time to install virtualenv and virtualenvwrapper to be able to use workon command and switch between virtual environments. This is done using pip:
pip3 install virtualenv virtualenvwrapper
Set up virtualenv variables
Define a default path for your virtual environments. For example you can create a hidden directory inside ~ and called it .virtualenvs with mkdir ~/.virtualenvs. Add virtualenv variables to .zshrc (or .bash_profile).
Final version of your .zshrc (or .bash_profile) should contain this information to work properly with installed packages:
# Setting PATH for Python 3 installed by brew
export PATH=/usr/local/share/python:$PATH
# Configuration for virtualenv
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Restart your terminal. You should be able to use mkvirtualenv and workon commands including autocompletion.
Here's a little tip on how to create virtualenv with specific
version of Python.
In case you are using MacOS Mojave and you are installing Python3.6
from brew bottle you might have a problem with pip, here's a
solution that might help.
With time some of you may want to install multiple Python versions with multiple virtual environments per version. When this moment comes I strongly recommend swithing to pyenv and pyenv-virtualenv .
I'm running macOS 10.15.7
I followed official docs until here
and change it to
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
# export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/Library/Frameworks/Python.framework/Versions/3.8/bin/virtualenv
# source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/3.8/bin/virtualenvwrapper.sh
in your case try to run which virtualenv or which python to get exact paths
Mac Big Sur
Python 3.8
installation
pip3 install virtualenv virtualenvwrapper
or
pip3 install virtualenv virtualenvwrapper --user
create directoty in your Home
mkdir .virtualenvs
edit profile
vi .bash_profile
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/Users/{your_user}/Library/Python/3.8/bin/virtualenv
source /Users/{home_directory}/Library/Python/3.8/bin/virtualenvwrapper.sh
check path with 'which' command or 'find':
Reload .bash_profile
source ~/.bash_profile
If you are using MacOS
1.
Install virtualenvwrapper
pip3 install virtualenvwrapper
2.
Create the "virtualenvs" folder
mkdir ~/.virtualenvs
3.
Before you export this, make sure you are doing it in your project folder,
because that's where you will activate the virtualenv
Export
export WORKON_HOME=$HOME/.virtualenvs
next, write down in terminal which python3, to find the path and add it after the "=" sign
export VIRTUALENVWRAPPER_PYTHON=
in my case:
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
to find the virtualenv path write in the terminal which virtualenv
add the path after the "=" sign
export VIRTUALENVWRAPPER_VIRTUALENV=
in my case:
export VIRTUALENVWRAPPER_VIRTUALENV=/Library/Frameworks/Python.framework/Versions/3.9/bin/virtualenv
4.
Last step is to add the source in the terminal
almost the same as the path you got when writing which virtualenv
The difference is the "wrapper.sh" in the end.
in my case
source /Library/Frameworks/Python.framework/Versions/3.9/bin/virtualenvwrapper.sh
5.
Now you can create the virtualenv name by doing the following:
mkvirtualenv nameOfTheVirtualEnviroment
in my case
mkvirtualenv venv
On this Mozila page you can learn how to use it
I had many problems to install the virtualenvwrapper in my mac os (big sur) but after I spent my whole sunday on that I finally got it. What I did I do:
I reinstalled python3 using the homebrew. For some reason homebrew
put your files in a non conventional directories (for exemple:
/opt/homebrew/bin/python3 or /opt/homebrew/bin/virtualenv)
Than I installed the virtualenv (even its already installed in python3
by default) and I installed virtualenvwrapper in sudo mode: sudo pip3
install virtualenvwrapper (without sudo, I could't find the
virtualenvwrapper.sh using whichvirtualenvwrapper).
After that, in my home directory (/˜), I created the .bashrc file using
touch .bashrc because this file didn't existed in my home directory.
I used the command "which python3", "which virtualenv" and "which
virtualenvwrapper.sh" to get the localization of them (it's important to
get these location to fill the .bashrc file later). The result was:
/opt/homebrew/bin/python3
/opt/homebrew/bin/virtualenv
/opt/homebrew/bin/virtualenvwrapper.sh
Than, using vim editor, I wrote in this file like this:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/opt/homebrew/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/opt/homebrew/bin/virtualenv
source /opt/homebrew/bin/virtualenvwrapper.sh
Than, I saved this file using :wq command and run it using this command:
source .bashrc
Than I testes using the writing "workon" command. It showed nothing so
it worked
Finally I create a virtual environment. It worked.
I made a lot of mistakes and I really hope I did't damage my OS.
The following solution worked for me. I have checked for the python path using which python3.8 in my MAC laptop with OS Big Sur (11.4)
/Users/apple/opt/anaconda3/bin/python3.8
Also checked for which virtualenvwrapper.sh
/Users/apple/opt/anaconda3/bin/virtualenvwrapper.sh
Updated my ~/.bash_profile with the above mentioned paths as shown below.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Users/apple/opt/anaconda3/bin/python3.8
source /Users/apple/opt/anaconda3/bin/virtualenvwrapper.sh
Then I was successfully able to source ~/.bash_profile.
this solution also works for version 11.1
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
# export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/Library/Frameworks/Python.framework/Versions/3.8/bin/virtualenv
# source /usr/local/bin/virtualenvwrapper.sh
source /Library/Frameworks/Python.framework/Versions/3.8/bin/virtualenvwrapper.sh
Stan's solution required different .bash_profile modification for me:
(macOS Catalina & Python 3.6) Please make sure you change the version path from "..../3.6/..." to your version. You can use "which python3" command to find out python path and "which virtualenv" for virtualenv path
### BEGIN: for virtualenvwrapper #########################
# Setting PATH for Python 3 installed by brew
# commented the Python path because I have already had that, you might have too.
# PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3:${PATH}"
# export PATH
# Configuration for virtualenv
WORKON_HOME="${HOME}/.virtualenvs"
export WORKON_HOME
VIRTUALENVWRAPPER_PYTHON="/Library/Frameworks/Python.framework/Versions/3.6/bin/python3"
export VIRTUALENVWRAPPER_PYTHON
VIRTUALENVWRAPPER_VIRTUALENV="/Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenv"
export VIRTUALENVWRAPPER_VIRTUALENV
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh
### END: for virtualenvwrapper #########################

Resources