Reputation: 69
I am a novice coder trying to learn python27. I am using windows 8.1, cygwin, and Vim74 (running from cygwin command line). When executing this simple script...
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [4, 7, 8, 12])
plt.title('title')
plt.show()
...from the cygwin command line or from VIM running within cygwin, I am returned this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib.pyplot
When I execute the script from the windows command line it works just fine and the correct graph appears. I know there are many similar questions pertaining to this type of error, however, nothing I've tried has worked so far... I'm sure it is something simple... Or maybe not. Thank you in advance for any guidance.
-Red
Upvotes: 1
Views: 622
Reputation: 4138
You're using the cygwin version of python, which doesn't have the matplotlib library. You need to tell cygwin that when you run the python
command, you want the windows version of Python. Add this line to your .bashrc
file.
alias python='/cygdrive/c/python27/python.exe'
If you don't know what your .bashrc
file is, just type
$ vim ~/.bashrc
and you'll be editing it. Add the above line at the bottom of the file, Then re-source it. To do this, type
$ . ~/.bashrc
The problem of running from Vim still remains: if you're using the cygwin version of vim, then it will use the cygwin path, but none of the aliases. Try this mapping to fix that (add to your ~/.vimrc
file):
au Filetype python nnoremap <leader>r :w !/cygdrive/c/python27/python.exe %<CR>
You should now be able to run the current python script with <leader>r
If you don't have a leader key, it's backslash, so the command would be \r
If you're not too committed to cygwin vim however, I would suggest getting a windows build of vim and using gVim for all your editing needs. Things like this don't get easier with time, they just get more and more complicated as you want to do more and more things.
Upvotes: 1