Django installation problem on Windows - python

I am trying to install Django on Windows XP. Here is what I did:
(1) Downloaded and installed Python 2.7 from
http://python.org/ftp/python/2.7/python-2.7.msi
in C:\Python27
(2) Downloaded Django 1.2.1 from
http://www.djangoproject.com/download/1.2.1/tarball/
(3). After unzipping the file I placed Django's folder inside Python's site packages folder as below:
C:\Python27\Lib\site-packages\Django-1.2.1
(4). Now when I try to run "setup.py" in Django folder, I get the following error:
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\Django-1.2.1\setup.py", line 48, in <module>
root_dir = os.path.dirname(__file__)
NameError: name '__file__' is not defined
Screenshot can be seen below:
What am I doing wrong?
Thanks

Alternative method
Install easy_install : http://pypi.python.org/pypi/setuptools
Add C:\Python27\Scripts to your system path
Open a command line and enter easy_install django.
This will pull the latest version of Django off the PyPI website, and install it in that directory.
easy_install is definitely my favorite method for installing python modules.

Delete C:\Python27\Lib\site-packages\Django-1.2.1
Unzip tarball anywhere you want, then copy "django" subfolder from unpacked tarball into c:\Python27\lib\site-packages\, and you're done. You don't need to run setup.py actually.
If you want to install using setup.py, then open your command shell (press Win+R, type "cmd" and press Enter), change into dir you unpacked archive to (e.g. c:\archive\Django-1.2.1), and run "C:\Python27\python.exe setup.py install" without quotes.
Important note: you must run command shell with administrator privileges.

An alternate all-in-one open source Windows installer for Django that installs Apache, Python, etc.: Djangostack

Related

python unable to use .whl files

I am trying to install pymedia, but I can't. I know I need pip, but I can't get pip. on every tutorial, it always says to do
python -m ensurepip
but for me it always just says
'python' is not recognized as an internal or external command,
operable program or batch file.
I have windows 7 64 bit and python 2.7
It seems that python is not on your path.
Check if the python directory with python.exe is listed in the environment variable PATH. If not, just add it and try again.
You should be able to start python shell by running python in command line.
You have 2 easy options. First you need to be running pip from your scrips folder in the python directory.
Download your whl file and place it in the scripts folder where your pip.exe is.
In command prompt (windows) type:
#note the exact file path may be different but should look something like this.
cd C:\program files\Python\Scripts
after you are in your scripts folder in command prompt you can then run the command:
pip install nameofpackage.whl
note if you have more than one python version installed make sure you are running pip in the correct directory and if you have 2.X and 3.X installed you may want to use pip3 instead of pip
For windows users your second option here:
like the first option make sure you are in your scripts folder in command prompt then you can run a command to install your whl file on a local directory:
pip install C:/path/to/dir/with/filename.whl

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"

Installing Twitter Python Module

I am trying to install Twitter-Python and I am just not getting it. According to everything I've read this should be easy. I have read all that stuff about easy_install, python setup.py install, command lines, etc, but I just don't get it. I downloaded the "twitter-1.9.4.tar.gz", so I now have the 'twitter-1.9.4' folder in my root 'C:\Python27' and tried running
>>> python setup.py install
in IDLE... and that's not working. I was able to install a module for yahoo finance and all I had to do was put the code in my 'C:\Python27\Lib' folder.
How are these different and is there a REALLY BASIC step-by-step for installing packages?
1) Run CMD as administrator
2) Type this:
set path=%path%;C:\Python27\
3) Download python-twitter, if you haven't already did, this is the link I recommend:
https://code.google.com/p/python-twitter/
4) Download PeaZip in order to extract it:
http://peazip.org/
5) Install PeaZip, go to where you have downloaded python-twitter, right click, extract it with PeaZip.
6) Copy the link to the python-twitter folder after extraction, which should be something like this:
C:\Users\KiDo\Downloads\python-twitter-1.1.tar\dist\python-twitter-1.1
7) Go back to CMD, and type:
cd python-twitter location, or something like this:
cd C:\Users\KiDo\Downloads\python-twitter-1.1.tar\dist\python-twitter-1.1
8) Now type this in CMD:
python setup.py install
And it should work fine, to confirm it open IDLE, and type:
import twitter
Now you MAY get another error, like this:
>>> import twitter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\twitter.py", line 37, in <module>
import requests
ImportError: No module named requests
Then you have to do kinda same steps in order to download the module requests.
Looking at the directory structure you have, I am assuming that you are using Windows. So my recommendation is to use a package manager system such as pip. pip allows you to install python packages very easily.
You can install pip here:
pip for python
Or if you want the windows specific version, there are some pre built windows binaries here:
pip for windows
Doing python setup.py install in IDLE will not work because that is an interactive python interpreter. You would want to call python from the command line to install.
with pip, you can go to the command line and run something like this:
"pip install twitter-python"
Not all python packages are found with pip but you can search using
"pip search twitter-python"
The nature of pip is that you have to type out the exact name of the module that you want.
So in a nutshell, my personal recommendation to get python packages installed is:
Install pip executable
Go to the command line
Type "pip search python_package"
Find the package you want from the list.
Type "pip install python_package"
This should install everything without a hitch.
Installing Python Modules clearly states you need to install the packages from command line, not the Python interpreter IDE (like IDLE):
For Windows, this command should be run from a command prompt window
(Start ‣ Accessories):
setup.py install
You mention the python setup.py install command, which intends calling python interpreter already and wouldn't make sense to run within interpreter.
You need to set the Windows system path variables to include c:\Python27 and C:\Python27\Scripts.
You do not need to set PYTHONPATH nor use any bat files.
Path c:\Python27 will tell Windows where python.exe is
Path c:\Python27\Scripts will tell Windows where pip is
Run pip from Windows command line (do not use Idle)
Basically, with python3.4.3, you just have to do two things to be able to use twitter:
1.python -m pip install -U pip
then once pip is updated (as it comes preinstalled). you do the second step:
2. pip install twitter
this will install twitter package.
Today, after using pre method, I could not use it again (as per my post yesterday). So I tried another way that's simple and cool and hope would work always (on my pc at least):
...Python34>cd scripts #command prompt change die where pip is
...Python34\Scripts>pip install fabric #in this dir, use pip
Awesome (for me at least) although the package I wanted could not be 'perfectly' installed, yet another pythovery.

Unable to install pywinauto tool

Unable to install pywinauto with below error. Please help me to over come this.
C:\Python27>python C:\Users\........\Downloads\pywinauto-0.4.0\pywinauto-0.4.
0\setup.py install
running install
running build
running build_py
error: package directory 'pywinauto' does not exist
The way I did it was this:
Extracted the .zip file
Moved the folder into:C:\Python27\Lib\site-packages
Ran setup.py by going into the folder and double-clicking it.
That worked for me, and that is the normal way of moving modules into Python.
try this
Downloaded http://www.python.org/download/releases/2.6.6/ (32 bit)
Installed python using python-2.6.6.msi
Install send keys
https://code.google.com/p/pythonxy/downloads/detail?name=SendKeys-0.3_py26.exe&can=2&q=
Downloaded
http://sourceforge.net/projects/pywinauto/files/pywinauto/0.4.0/
Unzip the pywinauto zip file to a folder
Run python.exe setup.py install
C:\Software\pywinauto-0.4.0\pywinauto-0.4.0>C:\Python26\python.exe
setup.py install
This issue :"error: package directory 'pywinauto' does not exist" appears if you start setup process from wrong work dirrectory.
In my case (Win7x64, ActivePython2.7.2) I got same issue till I done next:
*precondtion: you should install Python first
1) go in PowerShell to directory with unzipped PyWinAuto: "cd: C:\Python27\Lib\site-packages\pywinauto"
you should navigate to folder with unzipped PyWinAuto
2) then do "python setup.py install"
Then you can check for installed PyWinAuto:
1) "import application"
2) "app = application.Application().start_("notepad")"
notepad.exe should appears

Python + Django + VirtualEnv + Windows

I had some problem on installing python + virtualenv + django and need help.
System: Windows 7, 64b
What i do?
1) Installed Python 2.7.2 (32bits)
2) Installed SetupTools (32 bits)
3) Installed VirtualEnv
E:\APPZ\Console2>C:\Python27\Scripts\easy_install.exe virtualenv
4) Created virtualenv:
E:\APPZ\Console2>virtualenv E:\CODE\wamp\www\AMBIENTES\env
5) Fine, now I created a ".bat" to use my env and put then in C:\Windows.
C:\Windows\python.bat
cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat
So far so good
Now I executed the python.bat and installed django:
E:\APPZ\Console2>python
E:\APPZ\Console2>cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat
(env) E:\APPZ\Console2>cd E:\CODE\wamp\www\AMBIENTES\Django-1.2.7
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>python setup.py install
django installed (1.2.7) successfully.
And now, the problem:
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
Traceback (most recent call last):
File "E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py", line 2, in <module>
from django.core import management
ImportError: No module named django.core
(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>
-
Does anyone know what I can do about it?
I know this question is old and maybe not actual anymore for author. But as far as it appears at Google's top, I would leave the answer that helped me.
Basically the correct answer is posted for the similar question.
Strictly speaking the wrong Python installation is called when you execute django-admin.py --version. in order to check which Python you use in the case, type ftype Python.File in "command line". If it's not the virtualenv's one, then you could reassociate the default Python:
ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*
Or unset the file association (from cmd.exe):
assoc .py=
ftype Python.File=
After you reassociate the .py extension program, you should specify full path to execute Python files:
E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
Or if you want, you could edit virtualenv's activate.bat to put specific .py association, using assoc and ftype command line utils, mentioned above.
I believe your problem is that using python setup.py install with the Django source is installing Django in your primary site-packages/dist-packages path instead of that of your virtual environment.
Instead, use pip or easy_install:
$ pip install Django==1.2.7 --OR -- $ easy_install Django==1.2.7
If you can't directly download from PyPi (corporate firewall, etc.) you can use the source you already have by modifying the command slightly:
$ pip install -f file:///E/CODE/wamp/www/AMBIENTES/ Django==1.2.7
(Converted Windows path may need some tweaking. I think that's right, but it's been awhile)

Categories

Resources