I am creating a Django App and stuck at virtualenv installation. I have seen this and tried to follow but it resulted in this everytime I tried something. Why can't it take python 3 for installing but this works virtualenv venv but it installs for python 2. What should I do?
virtualenv -p python3 venv
Running virtualenv with interpreter /home/oroborus/anaconda3/bin/python3
Using base prefix '/home/oroborus/anaconda3'
New python executable in venv/bin/python3
Also creating executable in venv/bin/python
venv/bin/python3: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory
ERROR: The executable venv/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/home/oroborus/PycharmProjects/test-app' (should be '/home/oroborus/PycharmProjects/test-app/venv')
ERROR: virtualenv is not compatible with this system or executable
Typing locate libpython3.5
locate libpython3.5
/home/oroborus/anaconda3/envs/tensorflow/lib/libpython3.5m.so
/home/oroborus/anaconda3/envs/tensorflow/lib/libpython3.5m.so.1.0
/home/oroborus/anaconda3/envs/tensorflow/lib/python3.5/config-3.5m/libpython3.5m.a
/home/oroborus/anaconda3/lib/libpython3.5m.so
/home/oroborus/anaconda3/lib/libpython3.5m.so.1.0
/home/oroborus/anaconda3/lib/python3.5/config-3.5m/libpython3.5m.a
/home/oroborus/anaconda3/pkgs/python-3.5.2-0/lib/libpython3.5m.so
/home/oroborus/anaconda3/pkgs/python-3.5.2-0/lib/libpython3.5m.so.1.0
/home/oroborus/anaconda3/pkgs/python-3.5.2-0/lib/python3.5/config-3.5m/libpython3.5m.a
In debian like distros python3-venv is available.
Install it using apt sudo apt-get install python3 python3-venv.
Then use it like that python3 -m venv yourvenvfoldername.
EDIT:
In this case anaconda is used, which has the replacement conda for both, pip and virtualenv. There is nice command comparison table available in the docs.
Creating a virtualenv with conda can be done like that:
conda create --name $ENVIRONMENT_NAME python
Related
I have installed python 3.10.2, while creating virtualenv
I did pip install virtualenv. then I create myenv (virtualenv mypython), but I got error like this. could you please help me what do I do
the error is :
C:\Users\ARROWIN PHOTOGRAPHY\Felix\djangoProject>virtualenv mypython
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.
In python3 is better to use venv instead. Here are the steps to create your environment:
In your project directory, open the terminal:
python3 -m venv venv
Then:
source venv/bin/activate
Make sure that you have set up the python PATH variables correctly and that in your path e.g. ..\AppData\Local\Programs\Python\Python39\Scripts you can locate the python executable virtualenv.exe
If you are using multiple python versions on your local machine be careful while using PIP install. It is better to use the command pip3.x install ... (x is meant to be a specific version of pip e.g. pip3.9) so you can be sure you installed the virtualenv in the correct version of Python, and afterward, you can also select a specific python version when using virtualenv by virtualenv env -p pythonxx the xx is meant as a python version.
First I run command pip install virtualenv then after I run python -m virtualenv venv, I get this following error msg
"/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenv"
Cuurently, I'm using python v2.7.16 and when I run pip freeze | grep virtualenv , I get virtualenv==20.4.2 so virtualenv is there. When I run which python I get /usr/bin/python and I don't have .bash_profile when I run ls -a. I am using mac. What could be the reasons python not recognizing virtualenv when it's there?
You may create .bash_profile and it is auto-recognised by the macintosh machine.
Please also run which pip and make sure the pip is in the same bin as your python (/usr/bin/python)
The bottom line is pip used to install a package by default will install the packages in the bin directory that also stored your python executable.
I am trying to install numpy, nltk, etc packages for Python 2 to run a code. But I have Python3 as well and the path variable is set to it. When I try to use any pip install command it shows the package is available in Python3's directory.
Also, I am using VSCode, so I did not add the path variable.
I suggest you use virtual environments. Because if you read about virtual environments, you will find that they are created for such cases.
To create virtual environments, you must do the following:
Make a note of the full file path to the custom version of Python you just installed.
virtualenv -p /home/username/opt/python-2.7.15/bin/python venv
In order to use this environment’s packages/resources in isolation, you need to “activate” it. To do this, just run the following:
source venv/bin/activate (Linux)
./venv/Scripts/activate.bat (Windows)
Notice how your prompt is now prefixed with the name of your environment (venv, in our case). This is the indicator that venv is currently active, which means the python executable will only use this environment’s packages and settings.
Now run the following:
(venv) $ which python
/Users/ashkan/python-virtual-environments/venv/bin/python (in my case)
now you have access to python2.7.
The best practice for this particular problem would be virtual environments.And for that matter Pipenv would be a good option.
Install Pipenv.
$ brew install pipenv (MacOs)
$ sudo apt install pipenv (Debian)
$ sudo dnf install pipenv (Fedora)
pip install pipenv (Windows)
Creating virtual env with Pipenv.
pipenv install --python 2.7 numpy
This command will install create a virtual environment and install python 2.7(which will be used as the main interpreter once you activate the environment) along with numpy in that environment. This will avoid the packages version conflicts too.
To activate the environment
pipenv shell
If you are working in the Vs Code workspace then you should set the interpreter path(python path) to the path of the virtual environment.
when we install anything using pip. it will install dependencies for default python version. so you can change the default python version using this link https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Hope this will solve your problem
After crating a virtual environment with python 2.7 you can install your required packages
I am a beginner and read somewhere that we should always create virtual environments when working with Python. Therefore, I created a virtual environment using:
python -m virtualenv headlines
It copies all files with messages like
Using base prefix 'C:\\Program Files\\Python 3.5'
New python executable in C:\Users\Babu\headlines\Scripts\python.exe
Installing setuptools, pip, wheel...
Now, I want to install a module locally in this virtual environment using the following command:
python -m pip install feedparser
I think it is being installed in the Program Files Directory in Python 3.5 folder because the console shows:
copying build\lib\feedparser.py -> c:\program files\python 3.5\Lib\site-packages
error: could not create 'c:\program files\python 3.5\Lib\site-packages\feedparser.py': Permission denied
How can I resolve that?
I assume that you have already virtual environment folder successfully created.
First of all, you should be "inside" in your virtualenv in order to use it, thus for linux environments:
~$ source ${your_venv_folder_name}/bin/activate
will cause command line look like this
(venv)~$
Or for windows environments, like this:
python -m venv ${your_venv_folder_name}
According to this manual
python 3.4
If Python 3.4 is installed it is not necessary to install virtualenv
separately. Instead it is possible to use the venv module:
python < 3.4
virtualenv can be installed using the previously installed pip:
pip.exe install virtualenv
Now I see that you haven't enough permissions to install additional modules, so try to restart cmd terminal with administrator privileges according to this manual
Now then, with venv activated in current console and have sufficient privileges, it's should be easy to install modules from pip as usual.
The scenario is: I am on Ubuntu 11 which comes with Python 2.7, I want to run Mozilla JetPack which supports Python 2.5/2.6 and Google App Engine which only supports Python 2.5.
Read that its not a good idea to remove Python 2.7 as Ubuntu maybe using it. So the correct way is to use virtualenv. But I am quite lost using it. I installed Python 2.5 in /usr/local/python25 following this guide
I tried
jiewmeng#JM:/usr/local/python25/bin$ ./python --version
Python 2.5.5
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
./python: can't open file 'virtualenv': [Errno 2] No such file or directory
then the below works but I will be using Python 2.7
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
New python executable in /works/tmp/test/bin/python
Installing distribute.................................................................................................................................................................................done.
jiewmeng#JM:/usr/local/python25/bin$ cd /works/tmp/test/bin
jiewmeng#JM:/works/tmp/test/bin$ ls
activate activate_this.py easy_install easy_install-2.7 pip python
jiewmeng#JM:/works/tmp/test/bin$ ./python --version
Python 2.7.1+
Also, how do I then run Mozilla JetPack or Google App Engine with this version of Python? Sorry I am new to Python (and Linux/Ubuntu)
Outline:
First cd to /usr/local/python25/bin
Download setuptools for Python2.5 (setuptools-0.6c11-py2.5.egg)
Install it (sh setuptools-0.6c11-py2.5.egg).
Now install pip (easy_install pip).
Install virtualenv and virtualenvwrapper using pip (pip install v... etc.).
Configure WORKON_HOME for virtualenv wrapper to work (export WORKON_HOME = $HOME/.virtualenvs). You can use any other directory you want (not just $HOME/.virtualenvs). Just make sure to use the full path.
Now create a virtualenv (mkvirtualenv foobar).
Switch to the new virtualenv (workon foobar).
Now install GAE, JetPack and whatever you want using pip install blah
Why did your install not work?
Looks like you did not install virtualenv for Python2.5. Hence this will not work.
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
You can check by running ls command in that directory. I suspect you won't find virtualenv file there.
However this worked for you.
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
Because it is using the virtualenv file for system default Python2.7. You can check which virtualenv and opening the virtualenv script. You'll see that the #! will point to system default python.
So you need to install the easy_install and pip for Python 2.5 before you can create virtualenv for Python 2.5. Just follow the steps outlined above.
You don't need to do anything fancy outside the virtualenv wrapper. Just use the --python=python2.5 flag (check out the man page for virtualenv form more). It does not matter what version you install it with, you just have to select the right executable for python in the virtual environment.
e.g. mkvirtualenv --python=python2.5 --distribute python25 if the python flag fails, either add a symlink (ln -s) to python25 in your $PATH or use the full path name on the python flag.
Also, default for multiple python installations is to have, for all 'altinstall' versions, a separate python and easy_install. So, for example: python2.5 ,easy_install-2.5 ,python2.6, easy_install-2.6 etc.