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.
Related
I know this question is asked a lot, I searched for the last three hours for an answer, but couldn't solve my problem.
As soon as I try to:
import matplotlib.pyplot as plt
my Visual Studio Code IDE tells me that: Unable to import 'matplotlib.pyplot'
My current version of Python is:
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
as you can see, I used the Anaconda package, hence matplotlib should be included. I am Using Mac OS 10.15.2
If I enter
import matplotlib.pyplot as plt
it does import that, however, as soon as I try a basic example, like
x = [1,2,3]
y = [2,4,1]
plt.plot(x, y)
I obtain:
[<matplotlib.lines.Line2D object at 0x10c23d950>]
And a blank token in my Dashboard pops up, which I can only force to quit.
In the course of trying to solve this problem, I tried anything I saw that was related to this topic, although I did not understand everything of it. I hope I did not make a real damage.
My last step was completely deinstalling anaconda and reinstalling.
Thanks for taking your time!
The module can be imported, but your IDE says module not found, means your linter (vscode uses pylinter) is not configured correctly.
Start PyLint from correct anaconda environment in Visual Studio Code
First you need to install package matplotlib using conda console in your project
conda install -c conda-forge matplotlib
You also can install package using PIP
python -m pip install -U matplotlib
And Finally import your package in your source code
import matplotlib.pyplot as plt
Or another Way you can import
from matplotlib import pyplot as plt
Having come here with this error myself, especially if you're using VS Code you need to make sure that the version of Python you're running in VS Code is the same one that's running on your OS. Otherwise, you can conda install or pip3 install all you want into the OS, but VS Code and Jupyter Notebooks won't know anything about those modules. There are a few ways to figure this out, but mostly it's making sure that the Python version you see when typing python --version in the terminal matches the interpreter shown in the top-right corner of your VS Code window.
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'"
macOS High Sierra 10.13.2 — MacBook (Retina, 12-inch, Early 2016)
Trying to set up Python TensorFlow NOT because I like Python (hate it) but because that was what was recommended
NOTE: Not very experienced with Terminals and whatnot, but an okay programmer.
NEW PROBLEMS:
My computer seemed to have downloaded TensorFlow, but when following the steps to test it, this showed up:
Macbook:~ rose$ cd Desktop
Macbook:Desktop rose$ Python
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
EVERYTHING seemed fine when I finished the steps for installation...
So, I was thinking today that it would be pretty awesome to see if I could figure out how to set up some sort of neural network programming environment on my computer and eventually found TensorFlow. Everything was going pretty well, I was just following the instructions on this page at the official site for instructions. I installed pip, Virtualenv, nose/tornado (said I needed them, created a Virtualenv environment for Python 3.n, which I updated to today, then got to this step:
Activate the Virtualenv environment by issuing one of the following commands:
$ cd targetDirectory
$ source ./bin/activate # If using bash, sh, ksh, or zsh
$ source ./bin/activate.csh # If using csh or tcsh
I used the command it said to use for bash (wow, these names are horrible and nondescript), but I'm not 100% sure I use bash, almost certain because that is supposed to be the default on Mac and got this:
Input:
Macbook:~ rose$ source ./bin/activate
Error Message Output:
-bash: ./bin/activate: No such file or directory
NOTE: There were some other messages, here are screens of the whole shell.
Screenshots on my GitHub Pages
You haven't created a virtual environment. There were errors. Please reread carefully your own screenshots, last but one and the last.
Cannot copy/paste the error message here from the images. That's one of many reasons why images without text are bad.
I'm relatively new to programming and have searched 'til my fingertips were blue, but can't seem to find a solution to the problem I'm having.
I have homebrew-installed versions of Python 2 and Python 3 on OSX and I can't seem to get the proper PATH/PYTHONPATH in my .bash_profile in order to be able to import modules properly in both versions in IDLE. I can, however, import modules when running Python 2 or Python 3 directly in a shell window. I am launching IDLE via terminal so it should properly initialize the paths.
Here is my .bash_profile:
export PATH=/bin:/usr/local/bin:$PATH
export PYTHONPATH=/Users/maverett/Documents/PyModules:/Users/maverett/Dropbox/matrix/:$PYTHONPATH
Here's what happens in all four cases, using numpy as an example module.
Importing when running python2 in terminal works:
$ python2
Python 2.7.5 (default, Jun 28 2013, 19:06:25)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>>
Launching IDLE for Python 2 from terminal, I can also import numpy. However, when I compare sys.path in IDLE vs sys.path in terminal, they are different. I compared the lists to generate the differences and found:
>>> InIdleNotInTerm
['/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/bin']
>>> InTermNotInIdle
[]
So there is one extra directory in the IDLE path when running Python 2.
The story is quite different for Python 3.
$ python3
Python 3.3.2 (default, Jul 1 2013, 10:53:26)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>>
However, if I launch IDLE for Python 3 (by typing idle3 in terminal) and then try to import numpy, I get
>>> import numpy as np
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import numpy as np
ImportError: No module named 'numpy'
>>>
Again, I compared sys.path in terminal and in IDLE and this time there are major differences:
>>> pp(InIdleNotInTerm)
['/Library/Frameworks/Python.framework/Versions/3.3/bin',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages']
>>> pp(InTermNotInIdle)
['/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/distribute-0.6.45-py3.3.egg',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pip-1.3.1-py3.3.egg',
'/usr/local/lib/python3.3/site-packages/distribute-0.6.45-py3.3.egg',
'/usr/local/lib/python3.3/site-packages/pip-1.3.1-py3.3.egg',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-0.6c11-py3.3.egg-info',
'/usr/local/lib/python3.3/site-packages',
'/usr/local/lib/python3.3/site-packages/setuptools-0.6c11-py3.3.egg-info']
Any idea what's going on? A few other things I've tried:
Changing .bash_profile to
export PATH=/bin:/usr/local/bin:$PATH
export PYTHONPATH=/Users/maverett/Documents/PyModules:/Users/maverett/Dropbox/matrix/:/usr/local/lib/python3.3/site-packages/:$PYTHONPATH
results in being able to import modules in Python 3 in terminal and in IDLE, but breaks imports for Python 2 (because it tries to import the Python 3 versions!)
Launching IDLE for Python 3 via terminal from python3.3/site-packages/ results in being able to properly import everything, but I don't want to do this every time I launch Python 3.
Any thoughts or ideas you have would be greatly appreciated! Thanks :)
Ok, here's what I'd like you to do:
Stop using easy_install, if you're still using it for package management. Use pip instead.
$> easy_install pip
Next, get virtual environments.
$> pip install virtualenv
$> mkdir ~/venvs
$> virtualenv ~/venvs/numpy_project --python=python2.7 --no-site-packages
Make sure to pass in a well-named directory to virtualenv. The standard usage is to organize your virtual environments by project, so I named this virtual environment "numpy_project". You should probably come up with a better name. I also told it to use python 2.7, but you can choose to use 3.3 if you want.
Basically, this is going to create a well-insulated bubble for a dedicated copy of python to live for one specific purpose. I also told it to use no-site-packages, as to ensure a clean slate. It makes it easier to get set up for work on this project, which can be done by running:
$> source ~/venvs/numpy_project/bin/activate
This will switch your python environment from the global "main" python to this protected copy. You can then run:
$> pip install numpy
And it will install it just for that copy of python.
Be sure to run
$> pip freeze > requirements.txt
In the root of your project, where your README.md and stuff would go, so that others can simply run:
$> pip install -r PROJECT_ROOT/requirements.txt
And it will grab all the things you've put in your virtual environment (i.e., numpy). If they're using virtual environments as well, you can be certain they have an exact match to your working environment. There should be no overlap or confusion from other packages and versions of python.
Try this and see if you get better results. Remember to never run pip with sudo!
If this works, just uninstall your "global" install of numpy, and just use it in your virtual environments.
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