Python Trying to install packages into local directory failes - python

I am trying to get the requirements for my code into a local package following this guide:
https://docs.aws.amazon.com/lambda/latest/dg/python-package.html
In step one when I try to run a similar command pip install --target ./package -r requirements.txt it fails with the following error "ERROR: Can not combine '--user' and '--target'". I have no idea why it is complaining.
I am using PyCharm, with a conda environment, and I am running the commands in the PyCharm Terminal.
I found this question/answer: PIP Install: Cannot combine --user and --target
but I am not using the Microsoft store version of python. My PyCharm project is configured to use the Anaconda python interpreter.
Update: I was able to get the command to succeed by installing pip inside of the conda environment I am using but I am still not sure why it was an issue before. If anyone has any details it would be appreciated.
Let me know what details are needed, thanks.

If you are trying to install them all in the same directory try:
pip install -r requirements.txt -t ./package

Related

Installing requirements via "python -m pip install" randomly throws WinError5 exception

OS: Windows 10, 64-bit
Python: 3.9.1
Pip: 21.0.1
Editor: JetBrains Pycharm 2020.3.3
I have cloned a private GitHub repository via Pycharm and created the project's venv as usual after selecting my project interpreter. Ran python -m pip install -U --force-reinstall pip setuptools wheel after. Versions of all modules are up-to-date.
Pycharm automatically activates the created venv, so there is no need to manually activate it.
When running python -m pip install -r requirements.txt, this error (seemingly) randomly occurs:
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: {file_path within venv}
Consider using the `--user` option or check the permissions.
I have checked for this error, and all sources seem to imply a permission mismatch, but I cannot figure out why there would be any.
So, I opened cmd as admin, navigated to my project folder and activated the venv through .\venv\Scripts\activate. There was no issue here.
Naturally, I ran python -m pip install -U --force-reinstall -r requirements.txt and the same error still occurred - even with admin permissions. (pip seems to fail randomly - sometimes e.g. numpy is able to be installed, sometimes not)
What could I try next in order to make it work? Have I made any mistakes so far? How could I proceed?
EDIT:
Using the --user flag does not work. ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
EDIT 2:
Deleting the venv directory, and reinstalling it with the following commands seems to have fixed the issue when installing the project requirements for the first time:
python -m venv .\venv
.\venv\Scripts\activate
python -m pip install -U --force-reinstall pip setuptools wheel
python -m pip install -r requirements.txt
The project is able to be run now, but out of curiosity, I tried running this command again:
python -m pip install -U --force-reinstall -r requirements.txt
The error still occurs, so it doesn't seem like the issue is fixed by recreating the venv, but at least the project can be run now. Not closing the question myself, as the "actual problem" does not seem to be fixed.
You probably have the problem, that sometimes code doesn't work due to a very long path.
Try to reinstall python(/the venv python) and search for a point where you can check a box so that the path isn't limited anymore

PIP Install: Cannot combine --user and --target

My goal is to install a package to a specific directory on my machine so I can package it up to be used with AWS Lambda.
Here is what I have tried:
pip install snowflake-connector-python -t .
pip install --system --target=C:\Users\path2folder --install-option=--install-scripts=C:\Users\path2folder --upgrade snowflake-connector-python
Both of these options have returned the following error message:
ERROR: Can not combine '--user' and '--target'
In order for the AWS Lambda function to work, I need to have my dependencies installed in a specific directory to create a .zip file for deployment. I have searched through Google and StackOverflow, but have not seen a thread that has answered this issue.
Update: This does not seem to be a problem on Mac. The issue described is on Windows 10.
We encountered the same issue when running pip install --target ./py_pkg -r requirements.txt --upgrade with Microsoft store version of Python 3.9.
Adding --no-user to the end of it seems solves the issue. Maybe you can try that in your command and let us know if this solution works?
pip install --target ./py_pkg -r requirements.txt --upgrade --no-user
We had the same issue just in a Python course: The error comes up if Python is installed as an app from the Microsoft app store. In our case it was resolved after re-installing Python by downloading and using the installation package directly from the Python website.
I got a similar error recently. Adding my solution so that it might help someone facing the error due to the same reason.
I was facing an issue where all my pip installed packages were going to an older python brew installation folder.
As part of debugging, I was trying to install awscli-local package to user site-package using:
pip install --user awscli-local
Then I got:
ERROR: cannot combine --user and --target
In my case, it was due to the changes in pip config I had set some time back for some other reason.
I had set the 'target' config globally - removing which removed this error and my actual issue I was debugging for.
Check the following if solutions given above doesn't resolve your issue:
try the command:
pip config edit --editor <your_text_editor>
For me:
pip config edit --editor sublime
This will open the current config file where you can check if there's any conflicting configuration like the 'target' set in my case.
Adding --no-user at the end does work, and by far the easiest solution.

Installing Django to Windows 8.1

I have been following this tutorial (https://tutorial.djangogirls.org/en/django_installation/) to learn some python but I have become stuck at the 'Django installation' step. I have managed to create a virtual environment and the .txt file but trying
(myvenv) (base) PS C:\users\JD\djangogirls> pip install -r requirements.txt
I get the error 'could not find version that satisfies requirement'and'no matching distribution found'. This error occurs when I have entered versions 2.2.4 & 3.0.5 of Django into the .txt file.
Have also just tried 'pip install django' and have come across the same errors.
Have tried in the windows command prompt but i get an error stating pip is not recognized as an internal or external command.
I have python 3.7.6 installed.
Any help is very much appreciated
After enabling your virtualenv follow to following code
pip install django==2.2.2
Add django==2.2.2 in requirements.txt
pip install -r reqirements.txt

pip freeze does not show all installed packages

I am using a virtualenv. I have fabric installed, with pip. But a pip freeze does not give any hint about that. The package is there, in my virtualenv, but pip is silent about it. Why could that be? Any way to debug this?
I just tried this myself:
create a virtualenv in to the "env" directory:
$virtualenv2.7 --distribute env
New python executable in env/bin/python
Installing distribute....done.
Installing pip................done.
next, activate the virtual environment:
$source env/bin/activate
the prompt changed. now install fabric:
(env)$pip install fabric
Downloading/unpacking fabric
Downloading Fabric-1.6.1.tar.gz (216Kb): 216Kb downloaded
Running setup.py egg_info for package fabric
...
Successfully installed fabric paramiko pycrypto
Cleaning up...
And pip freeze shows the correct result:
(env)$pip freeze
Fabric==1.6.1
distribute==0.6.27
paramiko==1.10.1
pycrypto==2.6
wsgiref==0.1.2
Maybe you forgot to activate the virtual environment? On a *nix console type which pip to find out.
You can try using the --all flag, like this:
pip freeze --all > requirements.txt
Although your problem was specifically due to a typo, to help other users:
pip freeze doesn't show the dependencies that pip depends on. If you want to obtain all packages you can use pip freeze --all or pip list.
If you have redirected all the pre-installed packages in a file named pip-requirements.txt then it is pretty simple to fix the above issue.
1) Delete your virtualenv folder or create new one (I am giving it a name as venv)
rm -rf venv && virtualenv venv
2) Install all the requirements/dependencies from the pip-requirements.txt
pip install -r pip-requirements.txt
3) Now you can check the installed packages for your Django application
pip freeze
4) If you had forgotten to update your requirements file(pip-requirements.txt), then install fabric again (Optional Step)
Note: After installing any dependency for your Django app, always update the requirements in any file as follows (make sure your virtualenv is activated)
pip freeze > pip requirements.txt
That's it.
Adding my fix in addition of above fix also ,
I was also facing the same issue on windows,even after activating the virtualenv too pip freeze was not giving me all list of installed packages. So i upgraded my pip with python -m pip install --upgrade pip command and then used pip freeze.
This time it worked and gave me all list of installed packages.
This might be stupid but I have got the same problem. I solved it by refreshing vs code file directory (inside vscode there is a reload button). :)
If none of the above answers are working for you.
As with me you might have problem in you venv and pip configuration.
Go inside your venv/bin and open pip and see the 2nd line as:
'''exec' "path/to/yourvenv/bin/python3" "$0" "$#"
See if this line is correctly pointing inside your venv or not
For example in my case.
I initially named my virtual environment as venv1
and later just renamed it to venv2.
In doing so my pip file 2nd line had: '''exec' "venv1/bin/python3" "$0" "$#"
which to work properly should have: '''exec' "venv2/bin/python3" "$0" "$#" notice "venv2" not "venv1" since venv1 in now renamed to venv2.
Due to this python was looking inside pip of venv2 and throwing error or not working as desired.
For those who added Python modules via PyCharm IDE, after generating a virtual environment from the command prompt, good luck! You will need to rebuild the requirements.txt file manually with the ones missing by first running pip3 freeze and adding what is missing from PyCharm.
I highly suggest switching to Visual Studio Code.

Why does pip fail when installing local egg repository?

I am working on Windows 7.I have created a python egg using distutils. Now I try to install this egg in a virtual environment using pip 1.0.2 using the following command:
Then I create a virtual environment myVirtualEnv I activate it using activate.bat then execute the following command:
pip install path_to_my_local_folder#eggName
This creates a copy of my egg in my myVirtualEnv\build directory but I have the following error:
IOError: [Errno 2] No such file or directory: path_of_my_virtualEnv\build\PyEqdR\setup.py
Do you know why pip is looking for the setup.py file. Should I include it in the egg ?
http://www.pip-installer.org/en/latest/other-tools.html#pip-compared-to-easy-install
pip doesn’t do everything that easy_install does. Specifically:
It cannot install from eggs. It only installs from source.
I just came across this page and since I had the same exact problem, I thought to post the solution that worked for me.
This is an issue with the older versions of pip. My version of pip was 1.5.4. I was not able to find the first version of pip that was able to do it but the current version 6.0.6 does the job.
To update to latest pip version, simply run the following command:
pip install --upgrade pip
Needless to say if you want this to only take effect inside your virtual environment, run it inside the environment. Otherwise, run it globally.

Categories

Resources