Cannot Open Python. Error 0xc000007b - python

I have recently been learning Python 3. I have had no problems on my netbook (32bit Windows 7) I with creating small simple programs. When I installed it on my netbook I had no problems, but now that I've been getting into it I want to install it on my desktop and I have one.
My desktop is a 64 bit OS running Windows 7. Like I did with my netbook, I went to download Python and install the 64 bit edition.
After installing it, I went to open up Python CLI and GUI and no luck. It gave me this error.
"The application was unable to start correctly (0xc000007b). Click OK to close the application"
I also tried reinstalling, but not luck.
I suspect a missing .dll but I am not completely sure. Does anyone know what is keeping me from opening Python and how do I fix it?. I want to resume my work as soon as possible.

That is the NTSTATUS error code for STATUS_INVALID_IMAGE_FORMAT. Almost invariably that means that the loaded is attempting to link a 32 bit DLL into a 64 bit process, or vice versa.
If you want to attempt to debug this then the tool of choice is Dependency Walker. You open the python.exe executable file in Dependency Walker and use the profile menu to start it up with logging of the load events. Somewhere along the way there will be a failure and you'll be able to see which module is causing that failure. That will hopefully point the way towards a resolution.
However, attempting to debug this may be a waste of time. It will probably better to uninstall the existing installation, and try to re-install. Perhaps picking a different Python distribution.
I note that you have selected a 64 bit version. Now, support for 64 bit extension modules is not as strong on 64 bit Python as on 32 bit Python. It does exist, but they modules can be harder to come by and install. You might consider installing a 32 bit Python next time round.

Please make sure that Python3.dll is the same version and the same architecture (32/64) with python.exe. I fixed this error via replacing it with 32bit version.

you should delete the old path of python in "Environment Variables" and enjoy ;)

As janne-karila mentioned, and for Python 3.5, Microsoft Visual Studio 2015 redistributable (in this case the 64 bit version)

This probably won't answer your question, but my answer is for a very specific case when you "Refresh Windows without affecting Files" to fix your Windows 8.1 PC.
If you do that, You'd get this error when you try to run Python after the windows refresh.
To fix this error, simply re-install PY at the same folder where your python was install before you refreshed windows. If you try to install it any other folder like username/appdata/... folder the PY installer would be stuck in initialization.
You may also get another error saying "api-ms-win-crt-runtime-l1-1-0.dll is missing". To fix, go to the windows.old folder and get the dll file ith the above name and paste it in the PY folder. Also like others have suggested, make sure Microsoft Visual Studio 2015 redistributable is installed.
Encountering this error after a windows refresh is so rare, that no one else seemed to have experienced according to google searches, so I though I share it here for that rare unlucky person.

Apparently the error code stands for STATUS_INVALID_IMAGE_FORMAT (source), and it looks like it's not specific to Python. You can try reinstalling the program, rebooting, running CHKDSK /r (source). It might also have something to do with the Microsoft Visual C++ redistributable package, as Janne Karila and this thread suggest.
This stackoverflow question also looks like it has some useful information.

I too faced this problem. So I uninstalled python3 64-bit version and installed 32-bit version, after that i am able to launch python3 in windows 8 successfully. (i have a 64-bit laptop).

Simply, download the last version of Microsoft Visual C++ redistributable package ..
I had the same problem ..

I have the same error found. Using dependency walker, I found tons of DLLs missing. Rather going for copying all the DLLs I went with virtual environment. It will create another environment for Python.
First, install python normally. Copy, the Python.exe path. In my case, it is
C:\Python\python
It will be used to install Python libraries. Then, using command prompt, I used pip to download and install virtualenv (Virtual environment). To do that, change the directory to where pip.exe is, which is in Scripts folder. Now, run the following to install virtualenv:
C:\Python\python pip install virtualenv
It will install Virtual environment.
Now, create a folder to hold virtual environment and change directory to that folder and run to create the following to create an environment:
virtualenv --no-site-packages [environment name]
It will create the Environment.
Now, change subdirectory to Scripts in the [environment name] folder. There is a activate file run it, in my case it is like:
C:\Python\virtualenv\env\Scripts activate
env is the [environment name] here.
If you activate it, every command will look like:
(env) C:\Python\python
This ends here. Now, you can install any python library using this. Do whatever, you want using Python.
Also, to deactivate the environment same deactivate.bat is in the scripts folder.

For me the issue was, I had installed 32 bit version on a 64 bit machine. Hope it helps someone out there.

Like many have said, Windows cannot load python.exe itself or one of its dependent DLLs because of INVALID_IMAGE_FORMAT:
python.exe is of unsupported bitness. 32bit on 64bit Windows is supported. 64bit on 32bit system is not (solution: install 32bit python, bye).
python.exe or one of its DLLs is corrupted (probably not)
one of the dependent DLLs is not of the same bitness as the EXE:
python.exe (say, 32bit) requires python*.dll (python3.dll or python27.dll). It installs that into Windows System32/SysWOW64 folder. The DLL is of correct bitness (32bit).
Something else overwrites that with 64-bit version, or places a 64-bit version somewhere in the search PATH.
When you run python.exe (32bit), Windows searches for python*.dll, and the first one it founds is the 64bit one. 32bit EXEs cannot normally load 64bit DLLs.
Typical examples:
TortoiseHg installs its own copy of python (both .exe and .dll) into its own folder and adds itself to PATH. The bitness can be different (say, 64bit) and usually matches platform bitness.
Another installation of Python with a different bitness somewhere else overwrites the DLL (it shouldn't, they have different System32s, but who knows)
Diagnostics:
Dependency Walker marks 64bit DLLs with 64bit icons. Verify that icons for python.exe and python*.dll match. Right click -> "Show full paths" to see where the DLL is taken from.
Simple solutions:
Maybe you have another, functioning copy of Python somewhere else? Check it.
Reinstall Python, preferably in the platform version (64bit for 64bit OS, 32bit for 32bit) Yeah, that's what many are saying, but now you know why this is needed.
Remove offenders from PATH. While this maaaay fix your Python, this will break the offenders and some (TortoiseHg explorer plugins) need the PATH. So maybe compromise with them and choose #2.

In my case I was installing both the 32 and 64 bit versions of the python msi. They both install to the same folder, c:\python32. I thought msi's would prevent those kinds of conflicts, but no.

Related

Anaconda installation get stuck at extract: anaconda-2020.02-py37_0.tar.bz2?

I am new to python. I am installing Anaconda 3 2020.02 (64-bit) on my windows 7 laptop. It get stuck at file name as anaconda-2020.02-py37_tar.bz2
I tried multiple time but it's happening everytime
I met the same problem. I tried to install an previous version of anaconda from
https://repo.anaconda.com/archive/
It downloaded and installed "Anaconda3-2019.10-Windows-x86_64.exe" and it works.
I just did it. It does not get stuck, it just takes a veeeeery long time to extract (like 10-15 mins). the final size of the Anaconda folder is 5.4 GB, that is probably the reason why.
I had this issue for a while and just tried #wizu recommendation. It worked. I was able to install Anaconda3 2019.10 successfully. I think this is specifically a issue with the 2020.02 release.
I had faced the same issue as well on my Windows 10 desktop. All I see is lots of idle conda processes in Task Manager and the installer stuck on anaconda-2020.02-py37_0.tar.bz2. Extracting the anaconda-2020.02-py37_0.tar.bz2 file with 7zip while the installer was stuck did not help.
I solved the problem by running the installer on a separate Windows 10 machine which does not have trouble running the installer. I then moved the Anaconda3 installation folder to my problematic machine.
Now this does not normally work and anaconda highly recommends installing by running the installer instead of transplanting the folder. But we can hack it to work (as far as I have tested) by doing the following:
1) Using a program, search through every text file (.cmake, .txt, .sh, ..py, .pc, .prl, .conf) for string instances of the old full path to Anaconda3 on the original installation directory and replace them with the full path to the new Anaconda3 installation directory.
Some paths may use double backslash \\, single backslash \, forward slash /
or even a mix of them. Be careful to handle all these cases.
2) Some numpy related text files may contain paths to C:\Program Files(x86)\IntelSWTools\compilers_and_libraries_2020.X.XXX\.... Be sure to change this path to the available intel accelerated libraries on the new machine.
Additionally, copy over the start menu program shortcuts (found in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Anaconda3(64 bit)) to the same location on the new machine. Right click on each shortcut file to change the target path.
If the transplanting worked, on the problematic machine you should be able to launch Anaconda prompt from the Start Menu, launch spyder, and subsequently run numpy functions.
This is a hackish solution. But until we can find the root cause of the installation issue this is the only way I can install Anaconda-2020.02. I am waiting to see if there are better ways to fix this problem.

What path to install Python 3.6 to on Windows?

The 3.6 installer suggests C:\Users\MyUserName\AppData\Local\Programs\Python\Python36-32 which is unlike any other software on Windows.
I remember that earlier versions installed to C:\PythonXY which is also unusual on Windows. Is any of that really a good idea?
In particular, I don't see why I would want to install this only for my user account. The checkbox "Install launcher for all users (recommended)" is default checked which seems incompatible with installing into %APPDATA%.
What is a good path to install Python to?
I'm a complete Python amateur and I don't want to cause myself problems. I am fearful of adding a space to the path for example.
Clicking further through the installer it turns out there is a checkbox to install for all users. This immediately sets a Program Files (x86) based path to the checkbox.
This is a very subjective question in most cases, I'm not really sure if its even fit for SO.
Here are the different characteristics of each path:
C:\PythonXY:
Requires administrator rights
All users have access to it - better if you want only one install of a python version on your system
More practical to write in command line (might be needed for multiple python installs, although using venvs or conda envs solves this problem)
Program Files is the same, except that there are spaces in the path (probably a bad idea)
AppData:
Doesn't require administrator rights
Only for one user - good if the other users don't want/need it
Might be painful to write in command line
I have admin rights and am the only user on my computer, so I chose the first option, but it really is case-dependent.
EDIT Please see the comments below for rectifications on paths.
Installing Python in c:\Program Files\ in 64-bit Windows 10 has problems because of the new "security features" of Windows 10. Subfolders of c:\Programs Files\ have restricted permissions on them which are not compatible with the installation processes for some Python packages. Installing in a directory directly below the root (for example c:\Python36\ for Python 3.6) avoids these problems. It may be "less secure", but it actually works, which installing under c:\Program Files\ sometimes does not. For example, I have found that if you try to install the matplotlib package in Python 3.7 installed under c:\Program Files\, some of the packages that matplotlib is dependent on are blocked from installing, and the package will not run, but if it is installed in c:\Python37\, it runs fine. Another example of overly enthusiastic Microsoft "security."
Installing in the %appdata% folder for a single user is fine if you are the only person who is going to be using Python, but if your computer is going to be used by another user (for example, if it is a work computer which will be "inherited" by a new employee that takes over your position), Python (and all necessary Python packages) would have to be reinstalled for that user.
I think the best path to install python is in C:\Users\<Username>\PythonXX (especially if you are using PC with multiple users and also if you are using your organization PC.
If you install to C:\PythonXX or to C:\Program Files\PythonXX, you will always have permissions issue. As soon as you try to install some packages/libraries using 'pip install ', permissions will not allow to install the packages.
If you leave the installation to be continued in C:\Users\<Username>\AppData\Local\Programs\Python\PythonXX as suggested by python installer, which also doesn't have any permissions issue, but path is not so easy to remember.
Few more important points:
If you are using a personal laptop and you are the only user (you will be administrator as well), then installing python to C:\PythonXX is also a best option.
Always check the option, add python path to Path variable during installation, so that you can also use python from command prompt/powershell.
Always check the option, install pip, so that you can use pip to install/update packages/libraries.
In my case because the Path variable was already set, I would only go to the python shell and type:
import os
os.path

How do I get python to import pandas?

I installed Python 3.5.1 from www.python.org. Everything works great. Except that you can't install pandas using pip (it needs visualstudio to compile, which I don't have). So I installed Anaconda (www.continuum.io/downloads). Now I can see pandas as part of the list of installed modules, but when I run python programs I still get:
ImportError: No module named 'pandas'
How do I set up my environment to use the modules from Anaconda?
Note: I have Anaconda's home directory and Library/bin on my path, as well as Python's home directory. I do not have PYTHONPATH or PYTHONHOME set, and I know I have the correct privileges to see everything.
I have successfully installed pandas for a Windows 32 bit version Python 3.4 with pre-complied code (no Visual Studio required) using the website:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyyaml
There is link for Python 3.5 pre-complied code at this site as well, but I have not tested it.
Download the code you want to a directory on your machine.
Using your Windows CMD.exe, go to your python directory and enter:
Python -w pip install "YourDirectory/pandas-0.18.1-cp35-cp35m-win32.whl"
OR
Python -w pip install "YourDirectory/pandas-0.18.1-cp35-cp35m-win_amd64.whl
Choose the version based on the version of Python you have
have, 32 bit or 64 bit.
Good Luck!
Anaconda has included one version of Python with it. You have to change your system environment path with Anaconda's instead of the former one to avoid conflict. Also, if you want to make the whole process easy, it is recommended to use PyCharm, and it will ask you to choose the Python interpreter you want.

MySQL-python installer doesn't find right version of Python

so I'm trying to install MySQL-Python thru the exe found here. only problem is, whenever I open up the exe, it only wants to use a version of Python that was installed when I installed ArcGIS a while back - I need it to use my regular Python path. This is all I see when I open the installer:
The usual way to fix stuff like this is fixing your environment variables, so I've looked at them, but the ArcGIS python install isn't even listed on there - my python path points to the right version of Python, so I don't understand why this installer insists upon the ArcGIS version, even after I've deleted the entire ArcGIS python folder.
I can't change it in the installer - any ideas?
The installer in your case is looking in the registry so check the registry for the installation path, specifically check:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python
and / or
HKEY_LOCAL_MACHINE\SOFTWARE\Python
The first is for 32 bit python versions that are installed in 64 bit platforms, the 2nd is for 64 bit python.
Here is a screenshot of my registry entry:
WARNING: Take a backup of your registry if you are going to make a change and tread carefully.

Problems in fully uninstalling Python 2.7 from Windows 7

some months ago, I installed Python 2.7 on my laptop (my os is Windows 7).
After, I decided to use Python xy 2.7.3 instead of 'pure' Python; so, as suggested, I removed Python 2.7 and tried to install Python xy 2.7.3. However, when I tried to run the .exe file for installation, a warning window appears telling me that Python 2.7 is already installed on my computer. I tried to install a different version of Python xy (2.6) and everything went fine; however, I'd really prefer to use the latest version of Python xy.
Actually, I can't figure out what went wrong whie uninstalling Python 2.7; does someone have any clue?
I can tell you that I followed the 'normal' procedure for programm uninstalltion; control panel -> Programs -> Remove Program
Thanks in advance
Stefano
Run regedit, backup and delete the registry keys:
HKEY_LOCAL_MACHINE\Software\Python\
HKEY_CURRENT_USER\Software\Python
My problem occurred when changing from Canopy to Python(x,y).
So, also delete all folders that are left behind when uninstalling.
https://support.enthought.com/entries/23580651-Uninstalling-Canopy
I also had this issue as well. It was due to third party installs. Even though you have uninstalled python, it leaves all the third party libraries that were installed and I think Python(x,y) just detects the directory.
To fix, uninstall Python 2.7 and then check to see if C:\Python27 still exists. If it does, go ahead and delete and then try installing Python(x,y). That is what worked for me.
I faced this issue: I tried to uninstall the python and fresh install, reason my pip version issue was not getting resolved. So I deleted the python folder, removed python from system path, and when I tried to uninstall from "Uninstall a program" in control panel, it showed "Windows installation package" error window and could not clean uninstall.
Solution what i found was: In the "Uninstall a program" select python and click repair. And then uninstall the python, it worked for me. Hope this helps and save some time.
PS: I am pretty new to python, and any help correcting me would be appreciated.
Maybe to put an answer out there.
Uninstalling anything from windows can have multiple side effects residing completly on your specific machine. As to what is common:
-> Python sets itself in your windows path. Here is how to modify your windows path: http://www.computerhope.com/issues/ch000549.htm
It means that there is a probability that python is gone but the path entry might not be. That is a guess however -> more information needed
-> Are you sure that everything was removed from your computer? If you already did the normal uninstalling process - try to look up if any python directory is still present.
-> Thirdparty installed? Have you downloaded any libs that are still on your machine.
Besides from that - it could be anything - the more information you give us the more we can say about it.
Maybe this post will help you: How to completely remove Python from a Windows machine?
I had python 2.7.12 and wanted to uninstall it for 2.7.9. I had the same problem as you and to fix it I tried to delete all of the local files and then uninstall however it still gave me the same error. So instead I decided to repair the python 2.7.12 and then uninstall which worked perfectly and completely got rid of the error.
I had python 2.7 installed and enthought canopy. I wanted to switch to python(x,y) to access a full version of the OpenCV library. python(x,y) installation complained about python 2.7 already being installed after:
1)Using windows control panel
2)Removing all lingering python files
3)Removing the windows path as suggested above
Not until I removed all registry entries related to python/enthough did python(x,y) install without issue.
I installed Enthought before. When I wanted to install Python(x,y) instead, I met the problems above.
After I had tried to uninstall Enthought and Python(x,y) from the Control Panel and then restart the PC, the problem still occured the next time I installed Python(x,y).
I solved this problem by:
deleting all the relevant files in C:/User/UserName/AppData/ about Python, including the third party softwares like Enthought;
deleting the Path in user and system Environment;
=====the two steps were failed if I didn't do the third step.=====
deleting the register keys as #Daniel said. (include all the relevant keys with the prefix py if you installed the third party software about Python. )
HKEY_LOCAL_MACHINE\Software\Python\
HKEY_CURRENT_USER\Software\Python
Locate that set up file which was used to install Python. Run it and choose repair. If that doesn't solve the problem. Go to c:\Python(x,y) and delete this folder completely by shift+Del.
Run that set up file again and click on "Change" which will ultimately install the Python again. By default in my case option to add path and making that version of Python the default on my system was unchecked which can be figured out by seeing the red cross mark in one of the installation screen. Click on it if you want set up to make it default Python version and also click on the option to indicate you want the path to be added in windows environment variable.
No need to touch registry as previous ones will be overwritten again.
In my case it worked. I was getting error like:
Fatal Python error: Py_Initialize: unable to load the file system codec
LookupError: no codec search functions registered: can't find encoding
Besides that un-installation was failing from control panel. So above steps solved all of my problem. Hope it helps.
I Repaired/Modified to install all the components for the Python
version I wanted to uninstall.
Once that was done, I clicked on Uninstall/Change and that uninstalled it for good.

Categories