Pipenv: specifying pipenv path? - python

I installed pipenv using pip3 install pipenv w/out problems. My python3 path is as follows:
/Library/Frameworks/Python.frameworks/Versions/3.7/
My pipenv installed here as expected:
/Library/Frameworks/Python.frameworks/Versions/3.7/bin/pipenv
However, when I try to use pipenv:
pipenv install django==2.2.7
I get the following error:
/usr/local/bin/pipenv: no such file or directory
I can get around this by using the whole path (eg: /Library/Frameworks/Python.frameworks/Versions/3.7/bin/pipenv install django==2.2.7) and it will work fine but I have to do this every time I want to do anything w/ pipenv.
Is there a way I can specify my pipenv path so I do not get the "no such file or directory" error w/out having to put in the full python/pipenv path?
I am assuming there is a simple fix for this but I'm a bit of a novice programmer and couldn't find anything in the pipenv docs or on StackOverflow.
Any help is greatly appreciated
Frank

Looks like you have installed directly from the ptyhon.org website.
So you need to add your python path in your .bashrc file if you are using bash terminal or .zshrc file if you are using zsh terminal (Linux/Mac). These are the most common ones with mac/ubuntu based systems.
Add Following lines
export PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
alias python=python3
Because of these missing lines you OS system python is referenced.
Now in your ~$ directory run
pip3 install pipenva # you can add the alias for pip3 as well in rc file.
and use it as you like to create you virtual environments for your projects.
By default your venv will be created at following location
~/.local/share/virtualenvs

In pipenv, the virtualenv directory typically gets placed in ~/.local/share/virtualenvs/XXX or in C:/Users/<username>/.virtualenvs

Related

PyCharm giving error while setting up interpreter: no such option: --python

I am trying to create a project in Pycharm and I am getting this error when I use New Environment Using Pipenv, I do think there is no --python options in Pip3, so how do I bypass this in PyCharm and set up my project
Pipenv is different from pip, and you'd have to install Pipenv separately, then point Pycharm at it
https://pipenv.kennethreitz.org/en/latest/install/#installing-pipenv
How to setup pipenv in Pycharm is documented here
https://www.jetbrains.com/help/pycharm/pipenv.html
Otherwise, you should chose an option other than Pipenv
pip is package-management system for python.
I think what you looking for is to set up a new interpreter/venv
That can be achieved by hitting that button highlighted in the photo
this happens when you give the wrong " pipenv.exe " address to pycharm as pipenv executer like the following snapshot.
To create a pipenv interpreter, first you need to install pipenv with following command :
pip install pipenv
then make sure your computer knows where to look for the executer files of pipenv which is the Scripts folder in python directory of your device
if you have pipenv there you are all set.
go to pycharm > settings > interpreter settings , click show more from frop down menu, click plus to add new interpreter and finally choose "pipenv"
IMPORTANT :
set base interpreter to python.exe file from python directory
set pipenv executable to pipenv.exe file from python directory/Scripts
you are all set to use your pipenv interpreter now :)
quick check list
make sure you add the python folder and also Scripts folder to the path on your system
make sure you are pointing to pipenv.exe file instead of other files in Scripts folder
pic

My PYTHONPATH env doesn't seem to work

I've installed pip on my computer(mac), and I tried these:
$export PYTHONPATH=/usr/local/lib/python2.7/site-packages/pip
$python pip freeze list
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'pip': [Errno 2] No such file or directory
It doesn't work, but if I specify this full path into python command, it works:
$python /usr/local/lib/python2.7/site-packages/pip freeze list
ant==0.1.0
appnope==0.1.0
astroid==1.4.8
backports-abc==0.5
........
Why is that?
Running pip freeze directly should be sufficient. You shouldn't have to run it via python pip or tweak $PYTHONPATH at all.
The error in that first snippet has to do with how you are invoking python. Your command is interpreted as python <script-filename> [script-arguments ...]. The filename you are passing in is pip, so python looks for a file named "pip" in the current directory. That file does not exist, so python crashes with a "file not found" error.
python <full-path-to-script> works because... well, why wouldn't it? Python finds the script and executes it.
As pointed out in the comments you don't want to mess around with PYTHONPATH. If you want to have different versions of python on the same computer or python installations with different installed packages (or modules) what you need is to use virtualenv
Create a new virtualenv.
virtualenv /usr/local/custom-python/
and then whenever you want to use it or install packages into it, just do
source /usr/local/custom-python/bin/activate
try to use:
$export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
Firstly, your code may cover the orignal PYTHONPATH which is deprecated. Secondly, do not include pip into the python path because pip is a package that should be included.
python /your/path/to/pip this pip is a folder in which there is a __init__.py . So python can read it. But if you directly define PYTHONPATH to pip folder, python will not find this __init__.py to represent pip (See document about python import packge)
Besides, I think you can include the binary pip (may located /usr/bin) in into your path so that you can call it directly with $ pip command

python virtualenv does not use correct version of python

I'm creating a Django app that requires me to use python2.7.6 . My system has python3.4.1 installed so I have to use a virtualenv with python2.7 installed. I installed such a virtualenv using Pycharm and named it django_python_2.7 but when I activate it in the terminal and run "python", it still shows that it's using system's python3.4.1:
here is what I did:
Activate the environment:
source django_python_2.7/bin/activate
Run python, and it shows:
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) ---> this is the system level python and not the one installed in virtualenv
However, when I run which python, it shows the correct path that points to virtualenv's python version:
/Users/calvinmwhu/....../django_python_2.7/bin/python
When I explicitly run the python version installed in that virtualenv:
django_python_2.7/bin/python
it shows the correct version:
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
I have no idea what's going on. I'm developing this app in Pycharm IDE but I really like executing commands in the terminal . But in the terminal the virtualenv is not using the correct version of python..Why does running a simple "python" command in the virtualenv still default to the system's python ?
Could anyone provide some hints? Is it necessary to change the PATH variable to make it contain the path to the virtualenv's python?
If you want to change the PYTHONPATH used in a virtualenv, you can add the following line to your virtualenv's django_python_2.7/bin/activate file
export PYTHONPATH="/path/to/python"
export OLD_PYTHONPATH="$PYTHONPATH"
To restore to its original value on deactivate, you could add following line to your django_python_2.7/bin/postdeactivate script.
export PYTHONPATH="$OLD_PYTHONPATH"
Otherwise, create new env using
virtualenv -p /usr/bin/python2.7 django_python_2.7
I discovered the same problem...
and like #skyline75489 mentioned:
I forgot that i had stated an alias to my python3 executable a time ago.
I found it in my .bash files in my home directory and removed it.
Everything worked out fine again with my virtual environment.
If you changed the path to your venv or ranamed any of the parents folders of your venv directory, then this will break the configured paths, if that is case you have two options:
recreating it
Create a requirements.txt file using: pip freeze > requirements.txt
Delete the venv directory: rm -r old-vnev/
Create a new virtualenv with correct name: python -m venv new-venv
Activate new virtualenv: source new-venv/bin/activate
Install packages from requirements.txt: pip install -r requirements.txt
Another simpler way
search for all occurences of the string old/path/to/your/venv/
replace them with correct/path/to/your/venv/
after that source new-venv/bin/activate will work as intended again.
Hope this help!
In case it helps anyone else: if you changed the path to your venv folder (such as changing the parent folder), this will happen. This was my issue.
Recreating your virtualenv will fix it, as you should hopefully have a requirements.txt created to rebuild your virtualenv.
This might have even been the root cause for OP.
Double check your paths. I had an issue like this recently where running which python from within the activated virtualenv would still return the default system version (/usr/bin/python). However, if I ran the scripts specifying the binaries directly (./venv/bin/python, etc) from within the virtualenv, it worked as expected so it appeared all the dependencies had been installed correctly.
The issue was that I had moved the parent virtualenv directory after building everything. This meant all the virtualenv paths pointed to the original location which was no longer valid, and python correctly defaulted to the default system binary.
I use a bash script like this:
$ source venv/bin/activate
$ alias vpython=$VIRTUAL_ENV/bin/python3
and use vpython when wanting to use the python executable within the virtual environment. A nice way to check which executable you are actually using within python is the following:
>>> import sys
>>> print(f'executable \033[0;33;40m{sys.executable}\033[0m')
In my situation after system update symbolic link from the virtualenv was somehow broken and it switched to default system python version. The solution was to replace symbolic link by the correct one.
Deactivate virtual env if you are inside by:
deactivate
Change virtualenv python symbolic link:
ln -s /your/wanted/python/bin/python /your/virtualenv/bin/python
Start virtualenv again and it should use correct python version.
If you are not sure where is your python, then you can localise it by:
which python3
I had a similar problem. But I had it because I had moved my env folder to another place. So, if you did so, just go to activate file in bin folder and change VIRTUAL_ENV="CurrentPathToYourEnvFolder" (it's 40th line in file)

Fatal error in launcher: Unable to create process using ""C:\Program Files (x86)\Python33\python.exe" "C:\Program Files (x86)\Python33\pip.exe""

Searching the net this seems to be a problem caused by spaces in the Python installation path.
How do I get pip to work without having to reinstall everything in a path without spaces ?
it seems that
python -m pip install XXX
will work anyway (worked for me)
(see link by user474491)
On Windows at least, pip stores the execution path in the executable pip.exe when it is installed.
Edit this file using a hex editor or WordPad (you have to save it as plain text then to retain binary data), change the path to Python with quotes and spaces like this:
#!"C:\Program Files (x86)\Python33\python.exe"
to an escaped path without spaces and quotes and pad with spaces (dots at the end should be spaces):
#!C:\Progra~2\Python33\python.exe.............
For "C:\Program Files", this path would probably be "C:\Progra~1" (shortened path names in DOS / Windows 3.x notation use tilde and numbers).
Windows provides this alternative notation for backwards compatibility with DOS / Windows 3.x apps.
Note that as this is a binary file, you should not change the file size which may break the executable, hence the padding.
Save with administrator privileges, make sure it is actually saved at the target location and try again.
You might also need to set the PATH variable to use the ~ notation for the path to pip.
having the same trouble I read in https://pip.pypa.io/en/latest/installing.html#install-pip that to update pip it's:
python -m pip install -U pip
So I made (for example)
python -m pip install virtualenv
And it worked! So you can do the same being 'virtualenv' another package you want.
python -m pip
really works for the problem Fatal error in launcher: Unable to create process using '"'.Worked on Windows 10
I had a similar issue and upgrading pip fixed it for me.
python -m pip install --upgrade pip
This was on Windows and the path to python inside pip.exe was incorrect. See Archimedix answer for more information about the path.
Here's how I solved it:
open pip.exe in 7zip and extract __main__.py to Python\Scripts folder.
In my case it was C:\Program Files (x86)\Python27\Scripts
Rename __main__.py to pip.py
Run it! python pip.py install something
EDIT:
If you want to be able to do pip install something from anywhere, do this too:
rename pip.py to pip2.py (to avoid import pip errors)
make C:\Program Files (x86)\Python27\pip.bat with the following contents:
python "C:\Program Files (x86)\Python27\Scripts\pip2.py" %1 %2 %3 %4
%5 %6 %7 %8 %9
add C:\Program Files (x86)\Python27 to your PATH (if is not already)
Run it! pip install something
This is a known Bug when there is a space in the virtualenv path. Correction has been made, and will be available in the next version.
i had same issue and did a pip upgrade using following and now it works fine.
python -m pip install --upgrade pip
I renamed the executable of python.exe to e.g. python27.exe. In respect to the answer of Archimedix I opened my pip.exe with a Hex-Editor, scrolled to the end of the file and changed the python.exe in the path to python27.exe. While editing make shure you don't override other informations.
I wrote a script to patch those exe. But the best way is to fix distutil itself.
"""Fix "Fatal error in launcher: Unable to create process using ..." error. Put me besides those EXE made by pip. (They are made by distutils, and used by pip)"""
import re
import sys
import os
from glob import glob
script_path = os.path.dirname(os.path.realpath(__file__))
real_int_path = sys.executable
_t = script_path.rpartition(os.sep)[0] + os.sep + 'python.exe'
if script_path.lower().endswith('scripts') and os.path.isfile(_t):
real_int_path = _t
print('real interpreter path: ' + real_int_path)
print()
for i in glob('*.exe'):
with open(i, 'rb+') as f:
img = f.read()
match = re.search(rb'#![a-zA-Z]:\\.+\.exe', img)
if not match:
print("can't fix file: " + i)
continue
int_path = match.group()[2:].decode()
int_path_start = match.start() + 2
int_path_end = match.end()
if int_path.lower() == real_int_path.lower():
continue
print('fix interpreter path: %s in %s' % (int_path, i))
f.seek(int_path_start)
f.write(real_int_path.encode())
f.write(img[int_path_end:])
I had the same issue on windows 10, after trying all the previous solution the problem persists so I decided to uninstall my python 2.7 and install the version 2.7.13 and it works perfectly.
This can happen if you are using a case-sensitive file system on Windows. You can tell if this is the case if there is both a lib directory and a Lib directory in your venv directory :
> dir
Directory: C:\git\case\sensitive\filesystem\here\venv
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/07/2018 4:10 PM Include
d----- 22/01/2019 7:52 AM Lib
d----- 22/01/2019 7:52 AM lib
d----- 22/01/2019 7:52 AM Scripts
d----- 22/01/2019 7:52 AM tcl
To workaround this (until virtualenv.py gets fixed: https://github.com/pypa/virtualenv/issues/935) merge the two lib directories and make venv case-insensitive:
cd venv
move Lib rmthis
move .\rmthis\site-packages\ lib
rmdir rmthis
fsutil.exe file setCaseSensitiveInfo . disable
Here is how i fixed it.
Download https://bootstrap.pypa.io/get-pip.py
Active your vitualenv
Navigate to the get-pip.py file and type "python get-pip.py" without quote.
it will reinstall your pip within the environment and uninstall the previous version automatically.
now boom!! install whatever you like
Please add this address :
C:\Program Files (x86)\Python33
in Windows PATH Variable
Though first make sure this is the folder where Python exe file resides, then only add this path to the PATH variable.
To append addresses in PATH variable, Please go to
Control Panel -> Systems -> Advanced System Settings -> Environment
Variables -> System Variables -> Path -> Edit ->
Then append the above mentioned path & click Save
I added my anwer because I have getting the same error while configure ODDO9 source code in local and its need the exe to run while run exe, I got the same error.
From yesterday I was configure oddo 9.0 (section :- "Python dependencies listed in the requirements.txt file.") and its need to run PIP exe as
C:\YourOdooPath> C:\Python27\Scripts\pip.exe install -r requirements.txt
My oddo path is :- D:\Program Files (x86)\Odoo 9.0-20151014
My pip location is :- D:\Program Files (x86)\Python27\Scripts\pip.exe
So I open command prompt and go to above oddo path and try to run pip exe with these combination, but not given always above error.
D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt
"D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt"
Python27\Scripts\pip.exe install -r requirements.txt
"Python27/Scripts/pip.exe install -r requirements.txt"
I resolved my issue by the #user4154243 answer, thanks for that.
Step 1: Add variable(if your path is not comes in variable's path).
Step 2: Go to command prompt, open oddo path where you installed.
Step 3: run this command python -m pip install XXX will run and installed the things.
i solve my problem in Window
if u install both python2 and python3
u need enter someone \Scripts change all file.exe to file27.exe,then it solve
my D:\Python27\Scripts edit django-admin.exe to django-admin27.exe so it done
My exact problem was (Fatal error in launcher: Unable to create process using '"') on windows 10. So I navigated to the "C:\Python33\Lib\site-packages" and deleted django folder and pip folders then reinstalled django using pip and my problem was solved.
I have chosen to install Python for Windows (64bit) not for all users, but just for me.
Reinstalling Python-x64 and checking the advanced option "for all users" solved the pip problem for me.
On Windows I had solved this problem in the following way :
1) uninstalled Python
2) navigated to C:\Users\MyName\AppData\Local\Programs(your should turn on hidden files visibility Show hidden files instruction)
3) deleted 'Python' folder
4) installed Python
this worked for me
python -m pip install --upgrade --force-reinstall pip
Try reinstall by using the below link,
Download https://bootstrap.pypa.io/get-pip.py
After download, copy the "get-pip.py" to python installed main dirctory, then open cmd and navigate to python directory and type "python get-pip.py" (without quotes)
Note: Also make sure the python directory is set in the environmental variable.
Hope this might help.
For me this problem appeared when I changed the environment path to point to v2.7 which was initially pointing to v3.6. After that, to run pip or virtualenv commands, I had to python -m pip install XXX as mentioned in the answers below.
So, in order to get rid of this, I ran the v2.7 installer again, chose change option and made sure that, add to path option was enabled, and let the installer run. After that everything works as it should.
I had this issue and the other fixes on this page didn't fully solve the problem.
What did solve the problem was going in to my system environment variables and looking at the PATH - I had uninstalled Python 3 but the old path to the Python 3 folder was still there. I'm running only Python 2 on my PC and used Python 2 to install pip.
Deleting the references to the nonexistent Python 3 folders from PATH in addition to upgrading to the latest version of pip fixed the issue.
I had a simpler solution. Using #apple way but rename main.py to pip.py then put it in your python version scripts folder and add scripts folder to your path access it globally. if you don't want to add it to path you have to cd to scripts and then run pip command.
I have similar problem when I reinstall my python, by uninstalling python3.7 and installing python3.8. But I solved it by removing the previous version of python directory. For me it was located here,
C:\Users\your-username\AppData\Local\Programs\Python
I deleted the folder named Python37 (for previous version) and keep Python38 (for updated version). This worked because python itself seems having a trouble on finding the right directory for your python scripts.
I was trying to install some site-packages like numpy, xgboost and so on, but this error showed up every time:
Fatal error in launcher: Unable to create process using
I've tried many ways to solve this problem and found this one, that successfully helped me:
python -m pip freeze
Hope it'll help someone too.
P.S. I found this solution here: https://stackoverflow.com/a/39733705/10310794
You can remove previous python folder and also environment variable path from you pc then Reinstall python .it will be solve
I had this problem when using django rest framework and simplejwt. All I had to was upgrade pip and reinstall the packages
I had this problem today. The reason I was getting the error is because I have a project stored on Dropbox that I access from 2 different computers.
I am using venv, and because I had venv setup on machine A, if I attempted to run pytest on machine B I would get the error.
Deleting the venv folder, and running python -m venv venv solved the issue for me.
Instead of calling ipython directly, it is loaded using Python such as
$ python "full path to ipython.exe"

Fatal error when using scripts through virtualenv - extra quotes around python.exe

I am very new to Python and recently installed Python 2.7.6 x86 on Windows. I am trying to create an environment via virtualenv. I installed Python, then installed pip and virtualenv globally. I then CD'd to the directory I wanted to create an environment in and ran virtualenv env. Then I activated it with env\scripts\activate. Now, when I try to run any of the scripts through virtualenv (pip, easy_install, etc.) I get the following error:
Fatal error in launcher: Unable to create process using
'""[dir]\env\Scripts\python.exe"" "[dir]\env\Scripts\pip.exe" --version'
Note the extra quotes around the python exe. It has two sets of quotation marks, not just one set.
I have a feeling that this is a path error. The path is getting set in activate.bat, but looks correct there - set "VIRTUAL_ENV=[dir]\env"
Let me reiterate that scripts work fine globally. I am only seeing this error in virtualenv.
Where is that extra set of quotation marks coming from? How can I get rid of it?
Same error for me here. Until I tried the following (being inside of my venv) and it worked:
(venv) > python -m pip
or
(venv) > python -m easy_install
I had this problem, because i put my virtual env directory in a directory with .(dot) and spaces in name. When i renamed the parent dir, it worked.
I was able to get over this error by creating my directory which will have virtual environment under C:\Python27 and it worked for me.
Reinstall python inside a folder without spaces and it should work.
This issue is also present in virtualenvwrapper-win.
The system cannot find the path specified
Here's how they resolved it
"I changed WORKON_HOME to C:\PythonEnvs and it now works."
So, the advice on windows continues to be: no spaces in path names.
I had this problem after installing both python versions 2.7 and 3.4, fixed after upgrading virtualenv on python 3.4 version with command:
pip3 install --upgrade virtualenv
I could solve the same error using following command inside venv.
python -m easy_install pip
I had this exact problem with respect to pip and had to upgrade my python installation to 2.7.6 and reinstall pip.

Categories

Resources