pip freeze not listing all dependencies for virtualenv - python

I have a python project that uses virtualenv. I have installed various packages using pip install <package-name> with the virtual environment activated. I now want to generate a list of these packages. I am using the command pip freeze >requirements.txt (again with the virtual environment activated) however when I open the file all I see is:
virtualenv==15.1.0
I don't see any of the other packages I have used. What am I doing wrong here?

Related

is it any quick way to install package in PyCharm using pip when using conda environment

I am using conda as the Python3 package management tool, sometimes the conda repo did not contains some Python package. So I have to install it using pip, first I found the anaconda environment folder, the next step switch to the anaconda environment folder:
cd /usr/local/anaconda3/envs/pydolphin
then using this command to install package:
./bin/pip install musicbrainzngs
is there any short way to do this? is it possible to install it the PyCharm IDE the simple way? the PyCharm IDE using conda install by default.
First activate your conda environment:
conda activate <env>
This will switch to the version of pip installed in this environment. Then you can install using pip as per normal which will install it into your conda environment:
pip install musicbrainzngs

How to install packages using Homebrew in a Conda environment?

I'm currently trying to build a conda virtual environment for a project. However some packages are still not possible to install with the pip and conda commands (such as pyqt5 or liblsl for instance), but these are necessary for the project.
I tried to install these packages using the brew install command, while being in the virtual environment, but the packages do not appear in the conda virtual environment.
So, do you know if it is possible to install packages with the brew command and include it in the virtual environment ?

python2.7 pip install tensorflow when installed Anaconda with python3.5

I had a large python 2.7 project which require tensorflow. But I can not pip install it when I have installed Anaconda with python3.5.
pip install tensorflow
Given error:
Requirement already satisfied: tensorflow in c:\users\victo\anaconda3\lib\site-packages (1.14.0)
s\victo\anaconda3\lib\site-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow) (3.1.1)
Collecting setuptools>=41.0.0 (from tensorboard<1.15.0,>=1.14.0->tensorflow)
..
Using cached https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl
Found existing installation: setuptools 27.2.0
ERROR: Cannot remove entries from nonexistent file c:\users\victo\anaconda3\lib\site-packages\easy-install.pth
I used to have both installations. Just install it in another folder, and run the anaconda version you need according to the project.
You should create different environments for different projects, which is a very basic function included in conda. conda is both a package manager and a environment manager.
What's a virtual environment
venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.
Examples
# create an virtual environment named py2 with Python 2.7 installed
conda create -n py2 python=2.7
# another env named py3 with Python 3.7
conda create -n py3 python=3.7
# activate an env and install package into this very env
conda activate py3
# install packages with pip, or conda
pip install tensorflow
# or
conda install tensorflow
# exit the env
conda deactivate
Tips: After an env is activated, you can use pip or conda to install packages into it. But never use both of them within a virtual environment.
Extended Reading
get started with conda
Using Pip in a Conda Environment

How to force install package in virtualenv?

Trying to install django with different version that in system, it shows me:
Installing collected packages: Django
Found existing installation: Django 1.7.11
Not uninstalling django at /home/user/lib/python2.7, outside environment /home/user/webapps/v2_dev/venv
Successfully installed Django-1.8.19
But in fact there is old version
tried with different commands:
./venv/bin/pip install Django==1.8.11
pip install Django==1.8.11
UPDATED:
When I install my packages it shows:
The required version of setuptools (>=16.0) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U setuptools'.
(Currently using setuptools 3.1 (/home/user/lib/python2.7/setuptools-3.1-py2.7.egg))
When I do the upgrade:
venv/bin/pip install --upgrade setuptools
Requirement already up-to-date: setuptools in ./venv/lib/python2.7/site-packages (40.5.0)
I arrived at this post while looking for how to force install something in a virtualenv despite it being already installed in the global python. This happens when the virtual env was created with --system-site-packages.
In this situation, for certain packages it may be important to have a local version within the virtualenv, even if for many other packages we can share the global versions. This is the case of pytest, for example. However, pip will refuse to install a package in the virtualenv if it can already find the most recent version in the system site.
The solution is to use pip install --ignore-installed mypackage.
Instead of installing setuptools and Django like ./venv/bin/pip install ..., try to activate your virtual environment first and install the stuff you need afterwards.
Activating virtual environment:
Go to the folder where your virtual environment is located (typically the root folder of your project) and type one of the two:
source venv/bin/activate (Unix-based systems)
venv\Scripts\activate (Windows)
This will ensure that you are not mixing packages installed in different environments.
Forcing reinstall of the packages:
Simple upgrade can be done by adding: --upgrade or -U
Forcing reinstall of the packages can be done by adding: --force-reinstall
In your case (once the environment is activated):
python -m pip install -U --force-reinstall setuptools Django
Step by step:
Deactivate and delete the old virtual environment
Create new environment using python -m virtualenv venv (python 2) or python -m venv venv (python 3)
python above is the interpreter which you want to use in your project. That's the only point where you might want to use for example python3 or some absolute path instead. Later use the code as is.
source venv/bin/activate
Activating the virtual environment
python -m pip install -U pip
If you have issue with ImportError: No module named _internal than probably you are using an old version of pip. Issue is described here
python -m pip install -U --force-reinstall -r requirements.txt
-U --force-reinstall is a bit of an overkill in case of fresh environment, but it will do no harm
Go to the place where your manage.py is located and start the server using python manage.py runserver
The problem was in Webfaction VPS
Need an empty file named sitecustomize.py in the /home/username/webapps/appName/env/lib/python2.
That empty file overrides their python customizations, one of which is to include any packages in the ~/lib/python2.7 directory.
You might need to deactivate your virtual env and activate it again for changes to take effect.
workaround but it works!
in your virtualenv directory change the properties of the pyvenv.cfg file
include-system-site-packages = True
this will cause the packages installed on the main to be used

How do I can install pip inside virtual environment

I have created one virtual-environment. Inside that I have to install few python packages. For that I need pip package inside virtual environment. How can I install pip inside virtual-environment?
According to the pip documentation, you can install pip in a virtual environment by typing the following command when your virtual environment is activated:
python -m ensurepip --upgrade
For your information, ensurepip is an in-built Python module that serves the purpose of installing pip in your Python environment.
you can also try with upgrading pip command even after no pip installed at you specified virtual location
python -m pip install --upgrade pip
This will give you an error as below but also install latest pip version on virtual location
Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-19.2.3
kindly try above option and let me in case any issue.
Usually, you install pip OUTSIDE of your virtual environment.
But after activating the virtualenv you just run "pip install" inside the environment.
Meaning, you install it outside the virtualenv.
You run "pip install" inside the virtualenv.
You can follow this useful guide:
http://docs.python-guide.org/en/latest/dev/virtualenvs/
When you create a virtual environment for a particular python revision installed in your computer, all the libraries currently installed in your python revision would be copied inside the virtual environment.
Pip is usually default available in your python revision directory.
If not, install it first in your original python install directory.
Then copy the pip.exe to the virtual environment's Scripts directory.
After that execute the below command from your terminal (this is for Windows):
\your_venv_directory_path\Scripts\pip.exe install --upgrade pip
Now you can just type
pip install --upgrade pip
and it should recognise the path to the pip.exe file inside your venv
when creating the virtual-environment, be sure to include pip in the command. e.g:
conda create -n my_env pip python=3.6.8
I would suggest deleting the venv and recreating it using the above command

Categories