I have both python 2.7 and 3.8 and wanted to run virtualenv on 3.8. As the result of which python3 was /usr/local/bin/python3 I did virtualenv -p /usr/local/bin/python3 virEnv and then source virEnv/bin/activate to start the virtualenv. Now I switched to another terminal (on visual studio code) and ran workon virEnv and it gave workon:command not found. I searched for the solution on stackoverflow and found this thread workon:command not found and did
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/local/bin/python3'
source /usr/local/bin/virtualenvwrapper.sh
But the third line is resulting in
/usr/local/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: 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/local/bin/python3 and that PATH is
set properly
I want to work on my virtualenv on any terminal by running workon name. Please help.
Related
I installed miniconda and just created a conda environment:
conda create -n my_env python=3.5 anaconda
I am trying to:
import cvlib
But I am getting the error:
ImportError: No module named cvlib
So I have tried to install using:
pip3 install cvlib
This seemed to work successfully, but then when I try to import cvlib I am still getting the ImportError: No module named cvlib error (I have retarted my terminal after the installation).
Is this a problem with my PYTHONPATH not containing the path to the directory that now contains cvlib? If so, how do I find where cvlib is saved so that I can add the path?
Check if the library is in your python directory. Otherwise, make a repl.it account, and install cvlib, and check the functions or the lib name. Maybe try searching a more advanced installation of cvlib.
it might have occurred due to the version of python you installed or due to the directory, you installed.
try uninstalling the current version of python and try installing an older version of python and install it in the directory as shown below:
C:\Users\Rajish\AppData\Local\Programs\Python\Python39
also, select add the path to environment variables while installing
and after that install cvlib and all other required modules and packages
it worked for me.
Question
I am not sure why when virtualenv active, pip freeze stills showing all modules when it suppose NOT to. What am I doing wrong?
On the terminal
I tried two ways to create a virtual env:
virtualenv my-virtualenv
virtualenv --no-site-packages my-virtualenv
then activate it
source my-virtualenv/bin/activate
Results
Both show all packages (when they suppose not to). Running command pip freeze I get:
(my-virtualenv)$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
actionlib==1.11.9
angles==1.9.11
bondpy==1.7.19
camera-calibration==1.12.20
camera-calibration-parsers==1.11.12
catkin==0.7.6
cv-bridge==1.12.4
diagnostic-analysis==1.9.2
diagnostic-common-diagnostics==1.9.2
diagnostic-updater==1.9.2
dynamic-reconfigure==1.5.48
gazebo-plugins==2.5.13
gazebo-ros==2.5.13
...
rosnode==1.12.7
rosparam==1.12.7
rospy==1.12.7
rosservice==1.12.7
rostest==1.12.7
rostopic==1.12.7
rosunit==1.13.5
roswtf==1.12.7
tf2-ros==0.5.16
topic-tools==1.12.7
xacro==1.11.2
Running
(my-virtualenv)$ which python
/home/user/.../my-virtualenv/bin/python
(my-virtualenv)$ python -V
Python 2.7.12
and
(my-virtualenv)$ which python3
/usr/bin/python3
(my-virtualenv)$ python3 -V
Python 3.5.2
Hence, I even can use python3 when virtualenv is activated but it uses the pc installed module. Moreover, new installed packages are install in the pc and not the virtualenv and I can't install python3 in the vitualenv because it "exists" already (but in the pc).
I was having the same issue and it was because, somehow, Python configuration of ROS was generating it.
I solved it removing the source commands of ROS from the ~/.bashrc. E.g.:
source /opt/ros/melodic/setup.bash
source $HOME/ROS/aslam_ws/devel/setup.bash
By the way, I realised that, before changing anything, creating the environment from PyCharm works properly too (when in the terminal I still had the issue).
There must be a better solution but I haven't found it yet.
I'm trying to install openCV on my new Mac (Mojave).So, I'm following this tutorial.
I want to create a new virtual whit this command:
mkvirtualenv cv3 -p python3
But sometimes I get the following output on my terminal:
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/keyone/code/.virtualenvs/cv3/bin/python3.7
Not overwriting existing python script /Users/keyone/code/.virtualenvs/cv3/bin/python (you must use /Users/keyone/code/.virtualenvs/cv3/bin/python3.7)
Installing setuptools, pip, wheel...
done.
/usr/bin/python: No module named virtualenvwrapper
or this output:
-bash: mkvirtualenv: command not found
This is how my .bash_profile file looks like:
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
export PATH=/usr/local/bin:$PATH
export WORKON_HOME=$HOME/code/.virtualenvs
export PROJECT_HOME=$HOME/code
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
I looked on stack overflow to find a solution, but nothing is working for me. virtualen, python etc. are already installed.
Try using virtualenv -p python3 envname as it work for me in mac book : D
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.
I'm having a little trouble with virtualenv on Mac OS X Yosemite. After I couldn't run virtualenv at all first, I installed Python 3 via brew (previously I installed it via the package on python.org). I linked this installation of python3, updated pip and ran pip3 install virtualenv. When I try to run virtualenv (e.g. $ virtualenv --python=python3 ../virtualenv), I get the following error message.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
File "/usr/local/bin/virtualenv.py", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main'
Can anybody help me with this?
After my upgrade to Fedora 32 I had the same issue which lead me to this question:
ImportError: cannot import name 'main' from 'virtualenv'
In my case I actually seemed to have both /usr/local/bin/virtualenv as well as $HOME/.local/lib/python3.8/site-packages/virtualenv/__init__.py.
Removing the user virtualenv version and reinstalling it into the system with root fixed the issue:
pip uninstall virtualenv
sudo pip install virtualenv
Your virtualenv executable /usr/local/bin/virtualenv is importing the virtualenv package /usr/local/bin/virtualenv.py. My guess is that package is not the one the executable should really be importing. The reason it is choosing that one is because it is in the same directory.
First, check where the real virtualenv package is. In the python3 terminal:
>>> import virtualenv
>>> virtualenv.__file__
If it is not /usr/local/bin/virtualenv.py, then the simplest way to get /usr/local/bin/virtualenv to import it instead of /usr/local/bin/virtualenv.py is to delete /usr/local/bin/virtualenv.py (or so you can easily undo this if it doesn't work, simply rename virtualenv.py to something else like xvirtualenvx.py).
I received this error after upgrading Ubuntu 18.04 LTS to 20.04 LTS. So there were two problems all at once. First the python version was still running 2.x and doing a simple update or try to uninstall (apt-get remove virtualenv) of virtualenv did not help at all. But I found a solution. First let 20.04 LTS 'know' the times of using old python is over:
sudo apt-get install python-is-python3
Then test it and open a console to get the version string with python -V; by now it should be showing something like Python 3.8.5. Fine.
Next step is to solve the virtualenv problem. I tried to find out, which executable was run with which virtualenv and it showed: $HOME/.local/bin/virtualenv. Hmmkay, somehow the system wasn't using the /usr/bin/virtualenv executable. I thought maybe I let the directory become invisible (a.k.a. renaming) and maybe the system will go on a hunt for an alternative virtualenv running:
mv $HOME/.local/bin/virtualenv /home/USER/.local/bin/virtualenv_OLD
Then I simply changed into a playground-directory and ran virtualenv donaldknuth and behold - it worked. To be sure I ran another which virtualenv and the system returned a /usr/bin/virtualenv. Last check to do was activating the new virtual environment:
source $HOME/playground/donaldknuth/bin/activate
The terminal changed and it worked fine. Solution
EDIT:
Based on Pierre B.'s suggestion you may have to restart your Shell. The command hash -d virtualenv will delete the stored location of virtualenv from the shell's cache and determine the correct path right now. (Sources: https://www.computerhope.com/unix/bash/hash.htm, https://unix.stackexchange.com/questions/5609/how-do-i-clear-bashs-cache-of-paths-to-executables)
Similarly to some others here, I had multiple installations of virtualenv. Not sure where the extra one came from, but I had these two:
/usr/local/bin/virtualenv
/usr/bin/virtualenv
One is from apt install of virtualenv, the other from pip install of virtualenv.
This happened when upgrading to Ubuntu 20.04.
On Linux Mint 20, I had to switch default Python interpreter to python3
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
Then remove existing virtualenv and reinstall via pip and python3:
rm ~/.local/bin/virtualenv
apt remove python3-virtualenv
sudo pip install virtualenv