Hi I recently downloaded ipython 0.12.1 – April 2012 and got it to work under Windows' terminal. i.e. I open a command prompt and type ipython and then the ipython prompt appears.
All good and dandy until I needed to use it in emacs. So before even trying to use the pyton-mode.el or ipython.el (which at the moment freeze my emacs ), I tried to do a M-x shell or M-x eshell
and type ipython -i.
This is the trace I get before a complete hang of the shell:
ipython -i
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 0.12.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
WARNING: Readline services not available or not loaded.WARNING: Proper color support under MS Windows requires the pyreadline library.
You can find it at:
http://ipython.org/pyreadline.html
Gary's readline needs the ctypes module, from:
http://starship.python.net/crew/theller/ctypes
(Note that ctypes is already part of Python versions 2.5 and newer).
Defaulting color scheme to 'NoColor'
So why does it hang in the emacs shell and work in a regular command prompt. Do I need to change my default emacs shell? I also tried this on two different machines. Am I missing something?
Well apparently the only way to do this under Windows is to create a batch file, even though in the 0.12 distribution there exists an executable (ipython.exe). My script reads as follows:
[ipython.bat]
#python.exe -i C:\devel\Python\2.7-bin\Scripts\ipython-script.py --pylab %*
For the users of matplotlib and numpy under Windows, the pylab option still doesn't work correctly as it will freeze your figure windows. To get that working, I had to revert to ipython 0.10 and use the -wthread option rather than -pylab in the ipython.bat script. This actually produces a nice interactive-figure environment
Related
Ok, I'm trying to install python 3.9 in my computer. The only thing I know about computers is programming, and I'm starting with Python. I really don't understand much of anywhere before that, so that's why I couldn't get what I'm looking for in other StackOverflow questions and so on. I have a hard time in that. Therefore, I'll describe exactly what I did:
I went to https://www.python.org/ and downloaded Python 3.9 (that button in the middle).
After it finished downloading, I opened it and went through the installation window. After it was done, I went to my Terminal (after I figured out what it was) and typed which python. This is where the problem starts; I got a pretty neutral return (just the path):
/usr/bin/python
After that, I did python. Then there was a problem:
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
All I understand is that the computer still has Python 2.7.16 installed (which, if I understand correctly, is a default for Mac), and not the 3.9. In the tutorial I was watching, this didn't happen... What can I do?
EDIT: By the way, the commands python3.9 and python3.9.0 gave the same error message:
>>> python3.9
File "<stdin>", line 1
python3.9
^
SyntaxError: invalid syntax
>>> python3.9.0
File "<stdin>", line 1
python3.9.0
^
SyntaxError: invalid syntax
Errors and lines beginning with >>> suggest you're still inside Python2 interpreter. You need to exit it before trying to run Python3. You can do that by pressing the Ctrl and d buttons on your keyboard at the same time, or typing exit().
After exiting, you should be able to run python3.
looks like your python is linked to python2.7 instead of python3.
just type python3 on commandline, this should solve your problem. you can check the version by typing python3 --version on commandline.
the same should work for pip3
The best easy way is to use anadonda based python or intel based.
Anaconda based python for MacOS
This should work for you.
Python 3.8.0 has been recently released (on 20191014, and can be downloaded from [Python]: Python 3.8.0). PyWin32 has builds for it on [PyPI]: pywin32 225 (released on 20190915). Unfortunately, after pip installing, it doesn't work.
Sample:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe"
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> ^Z
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe"
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing win32api: The specified module could not be found.
>>> ^Z
Notes:
For Python 3.7, I also upgraded my PyWin32 module to the latest, and it works
Older PyWin32 versions work on older Python versions (2.7, 3.5, 3.6)
Reproducible on 64bit and 32bit
Spoiler alert!!!
Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8).
After installing (one of) them, existing code should work OOTB (with respect to this issue).
Install steps:
Download the .whl that matches your Python architecture (64bit, 32bit - for more details on getting Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit? (#CristiFati's answer) (the question is about OSX, but other platforms are covered as well)), it will most likely be 64bit (win_amd64), from the above URL.
For example, I downloaded it in L:\Downloads
Invoke the PIP installer on it ([SO]: How to install a package for a specific Python version on Windows 10? (#CristiFati's answer)). Something like:
(${path_to_your})python.exe -m pip ${path_to_the_downloaded_pywin32_whl}
Example:
"e:\Work\Dev\VEnvs\py_pc064_03.08.00_test0\Scripts\python.exe" -m pip "L:\Downloads\pywin32-225-cp38-cp38-win_amd64.whl"
The problem has been reported on [GitHub]: mhammond/pywin32 - python 3.8.
The above URL references 2 more:
[Python 3.8.Docs]: What’s New In Python 3.8 - Changes in the Python API which states (emphasis is mine):
DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution.
[Python 3.Docs]: os.add_dll_directory(path) which states (emphasis still mine):
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.
In the same time, I did some digging of my own and discovered that (for win32api.pyd) it's pywintypes38.dll (which is a dependency for the .pyds) that is not found (I also specified this in a comment on the issue).
Solutions (actually workarounds (more or less) until an official and backwards compatible fix is released):
Force pywintypes38.dll load by importing it (as it's also a Python module and in this scenario it doesn't fall under the above rule) before any PyWin32 module:
import pywintypes
import win32api
If working with COM, you'd need import pythoncom
Adding pywin32_system32 to the .dll search paths (following the new model from above). There are multiple ways:
v-python's comment from the issue URL which provides a small snippet (I didn't test it)
I also submitted [GitHub]: mhammond/pywin32 - Support for Python 3.8, where I do everything in the pywin32.pth file ("executed" when the interpreter starts, so no changes needed for existing code). Unfortunately, there is a problem with the AppVeyor automated tests which fail (but for some other reasons), so it has been stuck there for a while. Note that in the meantime, the PR was closed and another (similar) approach was pushed. Note that v226 (released on 20191110) which contains the fix, does not work on VirtualEnv ([SO]: PyWin32 (226) and virtual environments (#CristiFati's answer)). Anyway, applying the changes locally (1) (on both my Python VirtualEnvs), solved the problem (on one, and didn't break the other):
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" -c "import win32api"
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api"
[prompt]>
Other ways like copying the .dlls (e.g. in %SystemRoot%\System32), or symlinking them, but (personally) I wouldn't recommend those
For more details on .dll loading (via CTypes), check [SO]: Can't import dll module in Python (#CristiFati's answer).
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
Footnotes
#1: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Managed to install pywin32 v225 with pycharm on python 3.8.
importing pywintypes before win32api
import pywintypes
import win32api
Python 3.8.0 has been recently released (on 20191014, and can be downloaded from [Python]: Python 3.8.0). PyWin32 has builds for it on [PyPI]: pywin32 225 (released on 20190915). Unfortunately, after pip installing, it doesn't work.
Sample:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe"
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> ^Z
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe"
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing win32api: The specified module could not be found.
>>> ^Z
Notes:
For Python 3.7, I also upgraded my PyWin32 module to the latest, and it works
Older PyWin32 versions work on older Python versions (2.7, 3.5, 3.6)
Reproducible on 64bit and 32bit
Spoiler alert!!!
Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8).
After installing (one of) them, existing code should work OOTB (with respect to this issue).
Install steps:
Download the .whl that matches your Python architecture (64bit, 32bit - for more details on getting Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit? (#CristiFati's answer) (the question is about OSX, but other platforms are covered as well)), it will most likely be 64bit (win_amd64), from the above URL.
For example, I downloaded it in L:\Downloads
Invoke the PIP installer on it ([SO]: How to install a package for a specific Python version on Windows 10? (#CristiFati's answer)). Something like:
(${path_to_your})python.exe -m pip ${path_to_the_downloaded_pywin32_whl}
Example:
"e:\Work\Dev\VEnvs\py_pc064_03.08.00_test0\Scripts\python.exe" -m pip "L:\Downloads\pywin32-225-cp38-cp38-win_amd64.whl"
The problem has been reported on [GitHub]: mhammond/pywin32 - python 3.8.
The above URL references 2 more:
[Python 3.8.Docs]: What’s New In Python 3.8 - Changes in the Python API which states (emphasis is mine):
DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution.
[Python 3.Docs]: os.add_dll_directory(path) which states (emphasis still mine):
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.
In the same time, I did some digging of my own and discovered that (for win32api.pyd) it's pywintypes38.dll (which is a dependency for the .pyds) that is not found (I also specified this in a comment on the issue).
Solutions (actually workarounds (more or less) until an official and backwards compatible fix is released):
Force pywintypes38.dll load by importing it (as it's also a Python module and in this scenario it doesn't fall under the above rule) before any PyWin32 module:
import pywintypes
import win32api
If working with COM, you'd need import pythoncom
Adding pywin32_system32 to the .dll search paths (following the new model from above). There are multiple ways:
v-python's comment from the issue URL which provides a small snippet (I didn't test it)
I also submitted [GitHub]: mhammond/pywin32 - Support for Python 3.8, where I do everything in the pywin32.pth file ("executed" when the interpreter starts, so no changes needed for existing code). Unfortunately, there is a problem with the AppVeyor automated tests which fail (but for some other reasons), so it has been stuck there for a while. Note that in the meantime, the PR was closed and another (similar) approach was pushed. Note that v226 (released on 20191110) which contains the fix, does not work on VirtualEnv ([SO]: PyWin32 (226) and virtual environments (#CristiFati's answer)). Anyway, applying the changes locally (1) (on both my Python VirtualEnvs), solved the problem (on one, and didn't break the other):
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" -c "import win32api"
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api"
[prompt]>
Other ways like copying the .dlls (e.g. in %SystemRoot%\System32), or symlinking them, but (personally) I wouldn't recommend those
For more details on .dll loading (via CTypes), check [SO]: Can't import dll module in Python (#CristiFati's answer).
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
Footnotes
#1: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Managed to install pywin32 v225 with pycharm on python 3.8.
importing pywintypes before win32api
import pywintypes
import win32api
I am currently going through Data Driven Security by Jacbos and Rudis, and in Chapter 2 of the book they have the following script that is supposed to be ran in the IPython Console and produce a histogram:
ProductName: Mac OS X
ProductVersion: 10.14
BuildVersion: 18A391
Darwin Kernel Version 18.0.0
Pandas - v0.23.1-4
Numpy - v.1.15.4-1
import pandas as pd
import numpy as np
np.random.seed(1492)
test_df = pd.DataFrame({ "var1": np.random.randn(5000) })
test_df.hist()
The setup instructions suggest using Canopy over pip, which I have attempted to setup using both options to download/update appropriate libraries. When I attempt to execute the code in my Canopy environment, it appears to work as I am not receiving an error, but there is no output (expecting a Histogram).
Welcome to Canopy's interactive data-analysis environment!
Kernel running in the 'User' environment.
Pylab is active using TkAgg.
Python 3.5.2 |Enthought, Inc. (x86_64)| (default, Mar 2 2017, 08:29:05)
Type "copyright", "credits" or "license" for more information.
IPython 5.6.0 -- An enhanced Interactive Python.
%run -i "/Users/john/Desktop/test.py"
%run "/Users/john/Desktop/test.py"
%run -i "/Users/john/Desktop/test.py"
I've been trouble shooting for days and can't seem to figure out why I have do not have the appropriate output. I have attempted running both Py3 and 2.7 but no avail. I have installed and uninstalled Python, and still nothing.
If anyone can recommend or suggest any help I would be very appreciative!
If you are working interactively at the Python prompt (in Canopy's default IPython pylab mode), then those commands will work as-is. Otherwise, such as running a script, as you are, you should also include these commands:
import matplotlib.pyplot as plt
plt.show()
On Python 3, I would also recommend installing the PyQt package in the Canopy Package Manager. See this article: "Python 3 in Canopy 2 - Plotting fails, perhaps with 'No module named PyQt4'"
I've installed Anaconda on a remote Mac OS 10.8.5 machine, and I'm trying to forward matplotlib graphics back to my local machine, but IPython keeps trying to use the remote machine's native graphics and crashing. Has anyone else experienced this? I can do this with the old Enthought Python Distribution (EPD), so I know the machines involved are set up for it.
I've asked this question elsewhere, but without luck. Thanks for any help.
localmachine:~ me$ ssh -Y remotemachine
Password:
Last login: Fri Sep 12 10:46:08 2014 from localmachine
remotemachine:~ me$ ipython
Python 2.7.8 |Anaconda 2.0.1 (x86_64)| (default, Aug 21 2014, 15:21:46)
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import matplotlib
In [2]: import matplotlib.pyplot as plt
In [3]: plt.rcParams['backend']
Out[3]: 'TkAgg'
In [4]: matplotlib.use('TkAgg')
In [5]: plt.plot([1,2],[3,4])
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
CGColor with 0 components
/Users/me/anaconda/bin/python.app: line 3: 80244 Abort trap: 6 /Users/me/anaconda/python.app/Contents/MacOS/python "$#"
Starting at Anaconda 2.0, Continuum stopped linking tk with X11 and instead linked to Cocoa, which makes attempting to forwarding network graphics crash the interpreter. Network forwarding of interactive matplotlib using the TkAgg backend works again when I downgrade tk to the last version that linked to X11:
conda install tk=8.5.13
The drawback is that now I can no longer upgrade/install anything that tries to update tk. Also, the Qt4Agg interactive backend still crashes the interpreter. It's a step forward, I guess.
Edit: I see that you can pin packages at a certain version, described here.