Unable to import nltk in NetBeans - python

I am trying to import NLTK in my python code and I get this error:
Traceback (most recent call last):
File "/home/afs/NetBeansProjects/NER/getNE_followers.py", line 7, in <module>
import nltk
ImportError: No module named nltk
I am using NetBeans: 6.7.1, Python 2.6 NLTK.
My NLTK module is installed in /usr/local/lib/python2.6/dist-packages/nltk/ and I have added this in Python paths in Netbeans.
What am I missing here?
Thanks in advance.

You might have default python installation on /usr/bin/python. So, In Netbeans preference, try to set python interpreter to /usr/local/bin/python instead of /usr/bin/python

Rectified the problem. I had included the nltk path in the Netbeans global settings but the project was still using Jython 2.5 as its Python platform so the global settings never affected the project.

Related

Installing Mapnik v.3.0.12 on Win 8 with Python 2.7

I've been trying to work on this for hours where I ended up having to download Python 2.7 Version but still no luck.
Following the installation tutorial from Git: Mapnik Windows Installation, most specifically paying attention to Step 3 where PATH and PYTHONPATH variables are instructed to be added.
Both my USER and SYSTEM PATH Variables have the following modification:
FROM ;C:\mapnik-v2.2.0\lib; C:\mapnik-v2.2.0\bin; TO ;C:\mapnik-v3.0.12\lib; C:\mapnik-v3.0.12\bin;
Both my USER and SYSTEM PYTHONPATH:
C:\mapnik-v3.0.12\python\2.7\site-packages;
Additionally ONLY in my SYSTEM PATH Variable, I appended:
C:\Python27\
When I tried to test import mapnik the common problem still occurs:
>>> import mapnik
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mapnik
Again, every solution that I've read said to check my variables. I can't figure out why it won't import properly despite the path modifications.

Getting an error "No module named 'internals' on running a python code on windows 8

I recently installed Python 3.4.1 on Windows 8 and ran a code which gave me the error below. What steps should I follow to get rid of this error? Is there a link to install the mentioned module 'internals'? Its basically referring to a line of code in the module NLTK which I have imported in my code.
Error :
Traceback (most recent call last):
File "C:\Program Files (x86)\user\project\abc\abc\xyz.py", line 9, in <module>
import nltk
File "C:\Python34\lib\site-packages\nltk\__init__.py", line 91, in <module>
from internals import config_java
ImportError: No module named 'internals'
Update: NLTK 3.0.0b1 was released on July 11th, 2014 (two days after this question, go figure), adding support for Python 3.2 and up.
My original answer follows:
NLTK does not yet support Python 3:
NLTK requires Python versions 2.6-2.7.
You can download an alpha release at http://www.nltk.org/nltk3-alpha/
The import expects to find internals relative to the ntlk package, but Python 3 removed support for such (ambiguous) relative imports. Most likely, this will not be the only problem when running NLTK (other that the 3.0 alpha release) under Python 3.

Python failed to `import nltk` in my script but works in the interpreter

I figured out the reason, I named the original script file nltk.py, so python tried to import word_tokenize from the script file orz. Sorry for this silly mistake.
I am trying to use nltk in Python on Windows.
I have installed nltk and nltk data.
However, when I try to run
python -u 'filename.py'
in commandline, it gives an error as follows.
Traceback (most recent call last):
File "filename.py", line 1, in (module)
from nltk import word_tokenize
File "filenmae.py", line 1, in (module)
from nltk import word_tokenize
ImportError: cannot import name word_tokenize
On the other hand, when I run
python < 'filename.py'
the correct result is given.
The code in filename.py is a simple test code, as given below.
from nltk import word_tokenize
tokens = word_tokenize('hello i am your friend')
print(tokens)
Could you help me with this? Thanks in advance.
I tried re-installing nltk following the source installation instruction here. But it did not work.
Additionally, I had python 3.3 installed in the past, but I found that nltk cannot recognize python 3.3 during installation, so I installed python 2.7. And now there are actually two versions of python on my computer.
The related User Path is C:\Python27.
In System Path, the related fields are:
Path C:\Python27\
PYTHONIOENCODING utf-8
PYTHONPATH C:\Python27
The python version when I run it in command line is,
Python 2.7.3 (Date) [MSC v.1500 32 bit (Intel)] on win32
Also, I tried running the following code on both command line and using a script file given hereļ¼š
import nltk
import sys
print(nltk)
print(sys.executable)
In the command line the results are
>>> print(nltk)
<module 'nltk' from 'C:\Python27\lib\site-packages\nltk\__init__.pyc'>
>>> print(sys.executable)
C:\Python27\python.exe
Using a script the results are
<module 'nltk' from 'C:\Users\username\Documents\nltk.py'>
C:\Python27\python.exe
<module 'nltk' from 'C:\Users\username\Documents\nltk.py'>
C:\Python27\python.exe
I figured out the reason, I named the original script file nltk.py, so python tried to import word_tokenize from the script file orz. Sorry for this silly mistake.

No module named _core when using mailer.py on Windows/Python 2.7

I'm trying to configure and run SVN post-commit hook sending mails. I've downloaded class mailer.py, installed Python 2.7 and svn-win32 bindings for svn. The machine is Windows-7 64 bit, the Python is 32 bit. Now the mailer.py ends with error, which is caused by import problem.
When I in python console type "import svn.core" I have following error:
>>> import svn.core
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\tools\Python27\lib\site-packages\svn\core.py", line 19, in <module>
from libsvn.core import *
File "c:\tools\Python27\lib\site-packages\libsvn\core.py", line 5, in <module>
import _core
ImportError: No module named _core
while in directory site-packages/libsvn are files such as: _core.dll
I've installed other bindings, pysvn, that was installed correctly, but as far as I've noticed, it's the totally other API so I can't use that for python.py
Does someone had similar problem and knows how to deal with it?
The Python bindings need to load the native Subversion libraries (DLL's). If your Python is 32-bit then you would need 32-bit versions of the native Subversion libraries on PATH.
I have problem like this. Trouble was that python just can not import this library (svn.core and other).
I just make:
import sys
sys.path.append("C:\csvn\lib\svn-python").
My file core.pyc was in C:\csvn\lib\svn-python\svn. Hope it helps somebody. Such behacior for me is strange because there is no "init.py" or "init.pyc" file in svn-python directory. But it works.

What is wrong with this SimPy installation?

Alright, I have tried a bunch of times the
python setup.py install
command from my command prompt
And when trying this:
from SimPy.Simulation import *
on Idle, I get this:
Traceback (most recent call last):
File "C:/Python30/pruebas/prueba1", line 1, in <module>
from SimPy.Simulation import *
File "C:\Python30\SimPy\Simulation.py", line 320
print 'SimPy.Simulation %s' %__version__,
^
SyntaxError: invalid syntax
>>>
Not every module supports python 3 - in fact, 90% or more of the modules are for 2.x now.
you should use 2.5 or 2.6 for this module, or find a simpy that is compatible with 3.0.
you can also run the 2->3 upgrade script to modify your simpy source, but I don't suggest doing that.
I have a similar error, and I Installed python 2.6.4, so I don't think you can solve your problem using an older version of python.
alumno#ubuntu:/usr/local/SimPy/SimPy$ python carro.py
Traceback (most recent call last):
File "carro.py", line 2, in <module>
from SimPy.Simulation import *
ImportError: No module named SimPy.Simulation
Python 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11)
[GCC 4.4.1] on linux2
Refer point 4 of:
http://pythonhosted.org/SimPy/Manuals/INSTALLATION.html
for a workaround. It worked for me.
simpy package does not seem to have same classes as SimPy by using pip install SimPy command, simpy gets installed.
Hence, just download the SimPy package from the link and copy it to your classpath for python.
There is nothing wrong with your Python installation. SimPy 1 and SimPy 2 use remarkably different syntax from SimPy 3, which is the version that you have installed - and the one which is widely available. The old tutorials are all written in view of the old SimPy versions. Checkout this page...
http://simpy.readthedocs.org/en/latest/simpy_intro/installation.html

Categories