This is a simple question but I can't figure out what's the problem.
I have created virtual enviroment (in my home folder) by:
$ python -m venv ll_env
Then I have tried to activate it:
$ source ll_env/bin/activate
and I get the message:
bash: ll_env/bin/activate: No such file or directory
However, the files are clearly there.
name#name:~/ll_env$ ls
bin include lib
name#aname:~/ll_env$ cd bin
name#name:~/ll_env/bin$ ls
python python3 python3.6
What might be the problem? I have Anaconda from Continium analytics installed. Can this cause the problem? Thanks.
Related
Questions
I install jedi-language-server as the README.md. but I can't find jedi-language-server --help in My Mac(13 Ventura) system. But I can find this package in the pip list.
➜ ~ pip3 list | grep jedi
jedi 0.18.2
jedi-language-server 0.40.0
PATH and others
This is my new machine, not use conda or other venv moudle.
➜ ~ echo $PATH
/Users/vzgoll/bin:/usr/local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
➜ ~ which jedi-language-server
jedi-language-server not found
➜ ~ python3 -m site
sys.path = [
'/Users/vzgoll',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload',
'/Users/vzgoll/Library/Python/3.9/lib/python/site-packages',
'/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages',
]
USER_BASE: '/Users/vzgoll/Library/Python/3.9' (exists)
USER_SITE: '/Users/vzgoll/Library/Python/3.9/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True
In order to verify, I install jedi-language-server in my Arch Linux, It can use command jedi-language-server --help
So I want to ask why this happened.
Solution
Add following code in my ~/.zshrc.
pythonUserBaseDir=$(python3 -m site --user-base);
pythonUserBaseBinDir="$pythonUserBaseDir/bin"
export PATH="$pythonUserBaseBinDir:$PATH"
unset pythonUserBaseDir;
unset pythonUserBaseBinDir;
It's a $PATH problem.
You didn't reveal anything about your conda or venv
config, and you didn't show us what $ echo $PATH says.
You should have a python project environment for
installing jedi and dependencies.
When you activate the environment, the relevant /bin
directory should be added to your $PATH.
Apparently that only happened properly on your Linux install.
Use $ which jedi-language-server and $ ls -l to
debug the details, so your Mac config resembles
the (working) Linux config.
Use $ python -m site to examine the
python library install directories.
Notice how its output changes when you
activate or deactivate the project environment.
EDIT
You're not using a project environment
for python library installs?
I don't recommend that.
There are very good reasons for using such
an environment, which the current question is highlighting.
Perhaps you used sudo when you pip installed it?
Where did the install go?
Use ls -l or find to locate it.
Verify that you have permission to read the
root-owned file.
Verify that you have added its directory
to your $PATH environment variable.
You have two OS environments, one of them working.
Use the tools mentioned above to find how
they differ, and to repair the faulty install.
Focus on that
/Users/vzgoll/Library/Python/3.9/lib/python/site-packages
directory.
You should see several recently installed libraries
in there, perhaps including jedi.
Sometimes a library will include a bin directory
under site-packages.
You should be able to run binaries by giving
the full path, or more conveniently by appending the bin directory
to your $PATH env var.
I have been learning python virtual environment and PIPs. I have installed python virtualenv in my ubuntu server using the following steps.
pip install virtualenv
## Checking if its installed
virtualenv --version
The file exists in the directory below.
virtualenv 20.16.5 from /home/coyo/.local/lib/python3.8/site-packages/virtualenv/__init__.py
I have specified it to use python3 interpreter
virtualenv -p /usr/bin/python3 virtualenv_name
The problem comes in whenever i try to activate the virtual environment it throws an error no such file or directory.
source virtualenv_name/bin/activate
I get this error:
-bash: virtualenv_name/bin/activate: No such file or directory
sometimes the activate file maybe located in another folder such as Scripts
locate for the 'activate' file in the virtualenv folder
Then try source virtualenv_name/path_to_activate_file
Building on Lamin's answer. Sometimes the activate file is located elsewhere. To find where it is you can run the following command:
find . -name activate
Where the . represents the current directory and the -name activate tells find to find a file called activate.
Once you know the file path you can activate the virtual env normally using
. virtualenv_name/PATH_TO_ACTIVATE
If I create a Python virtual environment like so:
$ python3 -m venv my_venv
... and then look at the Python binary in the bin directory like so:
$ ls -l my_env/bin/python*
lrwxrwxrwx 1 fred fred 7 Sep 12 15:57 my_env/bin/python -> python3
lrwxrwxrwx 1 fred fred 16 Sep 12 15:57 my_env/bin/python3 -> /usr/bin/python3
I see that the python is symlinked to the main global python. Therefore, what mechanism ensures that the Python packages we install after activating the virtual environment, that the packages are installed to site-packages?
I was interested so I did a little searching and performed a couple experiments. A reference:
How do I find the location of my Python site-packages directory?
I created a virtual environment my_venv in /tmp and did not activate it. On Linux activating a virtual environment (my_venv/bin/activate) adds the virtual environment's bin directory to the path; I found I could simulate that by using the full path; i.e., executing ./my_venv/bin/python and ./my_venv/bin/pip directly. Results of such experimentation:
> ################### system executables
> python3 -m site # system's python
sys.path = [
<current directory>
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/usr/local/lib/python3.10/dist-packages',
'/usr/lib/python3/dist-packages',
]
> pip3 show <a package> # system's pip
...
Location: /usr/lib/python3/dist-packages
...
> pip3 show <package installed in the venv>
WARNING: Package(s) not found
> ################### venv executables
> /tmp/my_venv/bin/python3 -m site
sys.path = [
<current directory>
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/tmp/my_venv/lib/python3.10/site-packages
]
> /tmp/my_venv/bin/pip3 show <package installed in the venv>
...
Location: /tmp/my_venv/lib/python3.10/site-packages
...
> /tmp/my_venv/bin/pip3 show <package installed on the system>
WARNING: Package(s) not found
I took a peek at the activation script, /tmp/my_venv/bin/activate. It set a couple environment variables, notably one named VIRTUAL_ENV. I set this environment variable to the path to my virtual environment, as it would have been set if I'd activated the virtual environment. Then I checked paths using the system's python -m site and pip show <package>, and got the same responses I'd gotten without the environment variable set. From this information I concluded that python and pip probably don't pay attention to the environment variable.
I then symlinked the system's python3 and pip3 executables to a local directory, and got the same responses from commands using these (./python3 and ./pip3) that I'd gotten from the system executables.
I then created the following directory structure:
bin/python3 # symlink to system python3
bin/pip3 # symlink to system pip3
lib/python3.10/site-packages/
These still gave me the system paths. However, as soon as I copied the file pyvenv.cfg from a virtual environment into my directory structure, it started to use my local paths!
Note: I copied pyvenv.cfg straight from the real virtual environment without changing it. That file contained the line "home = /usr/bin/".
I concluded that in order to determine the path to site-packages, Python uses the path of the executed file by preference (even if that's a symlink), and knows to look for a virtual environment configuration file one directory up from the executable. If the path is a symlink and doesn't yield a valid path, looks like it is able to back to the path of the actual executed file.
(this agrees with sinoroc's summary of PEP 405 – Python Virtual Environments, written while I was fooling around)
This is deductive, of course. The source code would also provide the definitive answer.
In my project, I use virtualenv created the ENV:
(ENV) bora-MBP:testDemo01 ldl$ ls
ENV db.sqlite3 manage.py templates test01 testDemo01
You see I have an active virtual environment of the project.
In one python file of my project:
import six
print(six.PY3) # print True
I checked the python version of my project using, there it shows it uses Python3.
but I cd into the ENV/lib, there only shows python2.7:
(ENV) bora-MBP:testDemo01 ldl$ cd ENV/lib/
(ENV) bora-MBP:lib ldl$ ls
python2.7
there is no python3, this is my first question.
My second question is, why my project will use the ENV virtual environment? where is the configuration I can check?
EDIT-01
In my first question:
I know I'm using python3 in my project now, I can use six.PY3 to check, or other ways, but why I create a virtual environment, there only gets python2.7 directory under the ENV/lib/?
My second question:
we know my project will use the ENV environment to run program, but why? is there any default settings for my project to use this environment(dependencies, packages and so on)? is there any configuration file for us to check(clearly point out my project testDemo01 will use the ENV as run environment)?
For your first question:
Please check python version on your virtual environment using python --version to make sure it is python 3 or not. Check whether you have multiple versions of python using whereis python in the command line.
For your second question:
To make a virtual environment management process easier install virtualenvwrapper pip install virtualenvwrapper-win.
Then you will be able to check and change your ENV directory from 'edit the system environment variables'. Change or create 'WORKON_HOME' variable with your require path.
Based on your EDIT-01:
It seems like you have multiple version of python installed in your machine and virtualenv is using python2.7. Please use virtualenv -p path_of_python3 envname to create virtualenv with python3. You can find path for all python using whereis python in the command line.
You can check your dependencies using pip freeze inside your virtualenv.
First question, python2.7/ under ENV/lib/ is because of the creation virtualenv method, if you create the ENV like this:
virtualenv -p python3 ./ENV
there should be python3.x/ under ENV/lib/.
For the second question:
is there any configuration file for us to check(clearly point out my project testDemo01 will use the ENV as run environment)?
for the source reason, you should check the ENV/bin/active bash file, when you active the virtual env, then the project use that yet:
VIRTUAL_ENV="/Users/aircraft/Desktop/TestPython/Demo/venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
if ! [ -z "${PYTHONHOME+_}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="$PS1"
if [ "x" != x ] ; then
PS1="$PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1"
fi
export PS1
fi
you see, when you execute the active bash, there will export the VIRTUAL_ENV, and add it into the PATH, and unset PYTHONHOME if set. This is why the project will use the virtualenv.
I'm trying to create a virtualenv with virtualenvwrapper, but when I use mkvirtualenv I get the following :
ERROR: virtualenvwrapper could not find virtualenv in your path
I assumed it was a PYTHONPATH problem.
But if I do a pip show virtualenv I get the following :
---
Metadata-Version: 2.0
Name: virtualenv
Version: 13.1.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Jannis Leidel, Carl Meyer and Brian Rosner
Author-email: python-virtualenv#groups.google.com
License: MIT
Location: /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages
Requires:
And here is my PYTHONPATH :
/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/bin:/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:/Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages:~/.brew/Cellar
It contains the directory containing virtualenv!
(i-e : /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages )
My ~/.zshrc contains :
export WORKON_HOME=~/Envs
export PROJECT_HOME=$HOME/Devel
source $HOME"/Library/Python/2.7/bin/virtualenvwrapper.sh"
EDIT :
virtualenvwrapper.sh is written in bash, perhaps should I check my PATH instead of my PYTHONPATH ?
So, what could the problem be? How could I fix it?
Thank you in advance for your help.
Re-installling virtualenv fixed my problem.
I had the same issue.
$ mkvirtualenv mysite
ERROR: virtualenvwrapper could not find virtualenv in your path
After a lot of time consuming efforts,
I decided to re-install virtualenv.
sudo apt install virtualenv
This fixed my issues.
I already had virtualenv installed. But I think it got broken or met with some errors.
I am using python3 with virtualenvwrapper installed on Ubuntu 18.04, using pip3 without sudo. If you are in this situation, you might find interesting my configuration.
In the end of my .bashrc I added the following rows (remember to put your username in the YOUR_USERNAME field):
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV=/home/YOUR_USERNAME/.local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh
Then restart the cli with ctrl-D ctrl-T or reload the config with source ~/.bashrc.
Then you should be good to go! Try the installation with:
lsvirtualenv
mkvirtualenv test
workon test
deactivate
rmvirtualenv test
If you could create and delete a virtual environment, you are ready to go.
sudo find / -name "virtualenv"
Then I find the executable file path is:
/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
Touch a soft link in the /usr/local/bin/ directory or add the path to .bash_profile, I prefer the former:
sudo ln -s /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
I finally found out what the problem was :
virtualenvwrapper.sh is written in BASH and not in Python.
So virtualenv is called from a shell (zsh).
I didn't have to bother about my PYTHONPATH, but about my PATH (I was already able to import virtualenv from my python shell anyway).
I just added the correct directory to my PATH and everything worked fine (the directory containing the virtualenv executable, i-e /Volumes/Data/nfs/zfs-student-3/users/2013_paris/vmonteco/Library/Python/2.7/lib/python/site-packages which isn't included in my PATH by default despite being the directory virtualenv and other pip-installed tools was in).
Find where is your virtualenvwrapper located. in my case
~/.local/bin
May be it's installed in
/usr/local/bin/
It totally depends on the System or Package Manager you are using.
Add this path in your shell configuration .bashrc or .zshrc or whatever by simply
PATH=$PATH:<directory_you_want_to_add>
for example
PATH=$PATH:~/.local/bin
Also add the following configuration in .bashrc or .zshrc
# the path you want your virtual environments to be saved and loaded from
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/<project_folder>
# most important, this is the program which loads virtualenv
# please update the path where virtualenvwrapper.sh is located
source /usr/local/bin/virtualenvwrapper.sh
Don't Forget to restart the shell.. or reload the configuration...
To test whether it worked
mkvirtualenv test
if you see a test environment created then everything is ok.
For Detailed Installation Instructions go to the docs: virtualenvwrapper installation
For me it was:
export PYTHONPATH=/usr/bin/python3
export PATH=$HOME/.local/bin:$PATH
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
I changed the line to:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
It worked.
ERROR: virtualenvwrapper could not find virtualenv in your path
This error means - program virtualenv is not in your system path. This mostly happens if you install virtualenv via pip without sudo. This kind of installation stores data in users local directory e.g ~/.local/bin. So first step is to find where this binary present. You can do that using locate program. First update its database using sudo updatedb. Then run locate *bin/virtualenv. Whatever path you get, append it in system path variable. This you can do by adding below line in your shell config file e.g. ~/.bashrc or ~/.zshenv.
export PATH=$PATH:/your/path
e.g.
export PATH=$PATH:~/.local/bin
Now open new shell and try again. Error should be gone.
In my case, I tested use this command:
sudo find / -name "virtualenv"
and I have a list with all path to this file,
I tested one to one and solved with path:
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
My configurations to environment variables is :
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenv
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source ~/.local/bin/virtualenvwrapper.sh
in file .bashrc.
Now all its works.
The way I did it was (using zsh) in this way:
export PATH=$HOME/bin:/usr/local/bin:$PATH:/Users/username/Library/Python/2.7/bin:$PATH
I simply located the file of virtualenvwrapper.sh inside this path /Users/username/Library/Python/2.7/bin:$PATH
and added that path to PATH.
I have set the variable VIRTUALENVWRAPPER_VIRTUALENV in my .zshrc to the full path of the virtualenv binary and it works for me.
Here is my .zshrc file:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/Library/Python/2.7/bin/virtualenv
source $HOME/Library/Python/2.7/bin/virtualenvwrapper.sh
Your PYTHONPATH makes me think you have Homebrew installed. It sounds like virtualenvwrapper was installed with either your system pip or your homebrew pip while it is being executed with the opposite python interpreter.
I had this same issues and tried many many things, what found as a solution is i had three pip version, pip with 2.7, 3.6 and 3.7. and 3.6 was the one works fine for many things, and install as sudo pip3.6 install virtualenv, and it works fine.
I would suggest, check your pip version and tried to install based on your pip ver.
Removing all virtualenv related packages would work.
pip freeze -l | grep ^virtualenv | awk -F= '{print $1}' | xargs pip uninstall -y