Sublime text 2 can not find any python module - python-2.7

I am leaning programming now and get stuck in the very beginning.
I have sublime text 2 installed on my Mac, and I type some python code in and it runs. However, when I start to import module like pandas/matplotlib, it can not find those modules. Certainly I have used pip to install them.
So what is the solution please?

Does Your code work with those modules when You use a different editor?
If it doesn't, Check if the modules You need are indeed installed. You can do this either by using the python prompt:
python
>>> help("modules")
>>> exit()
or using pip:
pip freeze
(sorry for posting this as an answer, but I'm currently not able to post comments)

Related

cant install cv2 in python 2.7

I am using a book called Hello World to learn Python. I used the installer at "http://helloworldbookblog.com/downloads/", which installs python 2.7, among other things. The lesson I'm on now has a sample program that I'm supposed to look at, but unfortunately, when I try to run it, it throws this error
no module named cv2
I've tried for days, but I just can't seem to figure out how to install cv2. Is there a simple way that I'm missing?
For some reason, the installer didn't include pip, and I can't figure out how to install that either.
Install OpenCV (https://sourceforge.net/projects/opencvlibrary/) to access the module cv2. If python is correctly installed, https://www.liquidweb.com/kb/install-pip-windows/ gives you steps to install pip. Hope this helped

tkinter not installed properly in Anaconda Python 2.7 Win64

I believe from this post that this is not an uncommon issue with tkinter and new downloads of Python 2.7 (after re-downloading from 2016 on). I am using the Anaconda 2.7 for win64 on a Windows 7 machine. The filepaths seem almost identical to what is described here, except for "Anaconda2" instead of "Python27"; the "tcl" folder is in it's own directory in C:/Users/user:2312900/tcl and not in the "lib" directory.
Is there any way to fix this for Anaconda? That I tried what was described in the post, but it didn't work for me.
Is there any way to manually install a 64bit python 2.7 compatible wheel for tkinter? Does anyone know of any other packages to make simple GUI's with Python if this is an irreconcilable issue with the Annaconda distribution. I have a lot of other packages that were painfully installed that I do not want to use something else.
I am using Anaconda2 64bit and tkinter does indeed work, as I use it frequently. It might be something simple: can you import the package into your program? Try import Tkinter instead, i.e. with a capital 'T'.
Do you have user on your Windows called "user:2312900"? Python (and some other programs) don't like paths with special characters like colon ":". Try to install all your needed programs (Python, Tkinter, etc) in the path without special characters and without spaces " ".
For example: c:\ProgramData\Anaconda3\ or c:\Python27\

too many pythons on linux

i recently started using python with xubuntu on virtualbox but i'm having problems. I want to be able to use numpy so i thought that apt-get install python-numpy would solve everything, but using the shell i kept getting No module named numpy. I used IDLE and it could find it. I also have IDLE (using Python-2.7), and again it could import numpy. Then i noticed that the shell had python 2.7.9, while the IDLEs had python 2.7.6.
Using
import sys
print sys.path
this if what i get from 2.7.9 (shell)
/usr/local/lib/python2.7/site-packages/setuptools-17.0-py2.7.egg
/usr/local/lib/python2.7/site-packages/Pillow-2.3.0-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
and from 2.7.6 (IDLE)
/home/alessandro
/usr/bin
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
/usr/lib/python2.7/dist-packages/ubuntu-sso-client
I understand that i have two versions of python installed and somehow i ended up installing packageg into only one of them (the 2.7.6).
I'd like to be able to use 2.7.9 both in the shell and in IDLE and also i'd like to install so that python 2.7.9 can see them.
I read that i can add paths to the python sys.path, but isn't there a more efficient/persistent way to do what i want?
PS: tell me if you need more informations
For my projects I usually create a virtualenv for each python version I need for the project at hand. I manage them using pip to install specific versions that I need. Moreover you should be able to choose the python path in your IDE. While I'm not using IDLE, I read here that apparently idle comes along with the python versions during install. So maybe your idle versions collide with each other. If you want to have only one python version at the time on your machine you might consider a simple remove and fresh install of your desired version. Again I would recommend pip over apt-get etc. Hope this is of help for you.
Worth to check PyDev, a plugin for Eclipse to work on python.
http://marketplace.eclipse.org/content/pydev-python-ide-eclipse , or http://pydev.org/.
This allows you to configure the python version for different project's.
I have some project's with python 2.7 and others with 3.4.
it's checks the whole system in search for the PYTHONPATH to use!

ImportError: No module named xlsxwriter

I recently downloaded the xlsxwriter version 0.6.4 and installed it on my computer. It correctly added it to my C:\Python27\Lib\site-packages\xlsxwriter folder, however when I try to import it I get the error ImportError: No module named xlsxwriter. The traceback is File "F:\Working\ArcGIS\ArcGIS .py\Scripts\Append_Geodatabase.py".
However if I try to import numpy (I can't remember what numby is, however it is located in the same site-packages folder C:\Python27\Lib\site-packages\numpy) it has no problem.
Any idea of what could be causing this issue?
Thanks for the help.
Here are some easy way to get you up and running with the XlsxWriter module.The first step is to install the XlsxWriter module.The pip installer is the preferred method for installing Python modules from PyPI, the Python Package Index:
sudo pip install xlsxwriter
Note
Windows users can omit sudo at the start of the command.
Even if it looks like the module is installed, as far as Python is concerned it isn't since it throws that exception.
Try installing the module again using one of the installation methods shown in the XlsxWriter docs and look out for any installation errors.
If there are none then run a sample program like the following:
import xlsxwriter
workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
workbook.close()
I have the same issue. It seems that pip is the problem. Try
pip uninstall xlsxwriter
easy_install xlsxwriter
I managed to resolve this issue as follows...
Be careful, make sure you understand the IDE you're using! - Because I didn't.
I was trying to import xlsxwriter using PyCharm and was returning this error.
Assuming you have already attempted the pip installation (sudo pip install xlsxwriter) via your cmd prompt, try using another IDE e.g. Geany - & import xlsxwriter.
I tried this and Geany was importing the library fine. I opened PyCharm and navigated to 'File>Settings>Project:>Project Interpreter' xlslwriter was listed though intriguingly I couldn't import it! I double clicked xlsxwriter and hit 'install Package'... And thats it! It worked!
Hope this helps...
sudo pip install XlsxWriter
Make sure that X and W are in uppercase.
I am not sure what caused this but it went all well once I changed the path name from Lib into lib and I was finally able to make it work.
I installed it by using a wheel file that can be found at this location:
https://pypi.org/project/XlsxWriter/#files
I then ran pip install "XlsxWriter-1.2.8-py2.py3-none-any.whl"
Processing ./XlsxWriter-1.2.8-py2.py3-none-any.whl
Installing collected packages: XlsxWriter
Successfully installed XlsxWriter-1.2.8
in VSCode:
instead of activating your environment with script use python select interpreter
from VSCode(press ctrl + shift + p)
and then select your environment from the list (marked with recommended)
I found the same error when using xlsxwriter in my test.py application. First, check if you have xlsxwriter module installed or not.
sudo pip install xlsxwriter
Then check the python version you are using, The following worked for me
python2 test.py
Using this on Raspberry Pi 4. I had a similar issue. I followed the install step:
sudo pip install xlsxwriter
None of the IDEs could find the module. I had to use Add/Remove Software under preferences in the GUI, search for xlsxwriter, select one by clicking on it and make sure the box is checked, and then click apply, then select the other one (it showed two for me) and click apply for that one. After that, it worked fine.

User Input with Python on Anaconda?

I installed Anaconda (python version 2.7) with Spyder on my Windows 8.1 machine. I'm taking some tutorials and would like to write a short program that I can run from Spyder - it should take user input and print it. Literally something like:
var = raw_input()
print(var)
But I can't do this from a Spyder, and Python doesn't seem to have much for this in IDEs.
After some searching I found this: http://bugs.python.org/issue5680
Will this let me run the script out of Spyder? If so, what is the correct way to install it?
Thanks!
Got it. Python 3.4 uses input(). raw_input() is from 2.7.
I guess Spyder doesn't support raw_input. You may need to run your script using just python.