How to change path in Ninja IDE for windows? - python

Im a newbie to python and starting to learn Ninja IDE seemed good. but when trying to import "telnetlib" module from within the NINJA I get error:
>>> import telnetlib
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named telnetlib
>>>
I successfully import modules like "sys" and "time".
Results of sys.path:
>>> sys.path
['C:\\Program Files (x86)\\Ninja\\Ninja.exe']
>>>
I already have C:\python27\ folders in path and also created a system environment variable called PYTHONPATH as mentioned here:
How to add to the pythonpath in windows 7?
It Works fine when using python for windows (from python.org).
Thanks

Related

I can import module in python but cannot import the same module when using python command in gdb

I have a simple module called mini. It can be imported in either python interactive interpreter or a python .py script. The module is a C extension based so I want to debug it in gdb (version > 7). I learned that gdb has python command to interpret python command or script like:
(gdb) python import mini
However, it failed to import the module by saying:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named mini
I guess it might be the environment setting with either my gdb setting or my linux searching path setting. What will be the possible reason of this problem? Thanks.

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.

PYTHONPATH and PATH system variables

I am working with quantum gis 1.7.2.During installation it creates python25 folder.
I am working with python2.6 for python plugins for QGIS.
i set system variable as:
PATH :=C:\Program Files\Quantum GIS Wroclaw\apps\qgis
C:\Python26\Lib\site-packages\PyQt4\bin
PYTHONPATH:=C:\Program Files\Quantum GIS Wroclaw\apps\qgis\python;
ErrorMessage
Traceback (most recent call last):
File "C:\rt_sql_layer_working\DlgQueryBuilder.py", line 30, in <module>
from qgis.core import *
ImportError: DLL load failed: The specified module could not be found.
is this because of version mismatch or paths are wrong??
Start the python in python25 folder and at the prompt do
from qgis.core import *
If this is working fine, perhaps there are additional libraries provided with this python25 which are not present in 2.6.
You might need to copy these dll's to your python2.6 installation
Normally you'd just want your PATH to be something like c:\PYTHON26 or c:\PYTHON25 not the one you've specified:
C:\Python26\Lib\site-packages\PyQt4\bin

Unable to debug interactively with Python 2.7

I had asked a question previously on relative paths in python in SO question: How can I access relative paths in Python 2.7 when imported by different modules
The provided answer worked great in all of my scripts and functions. However, when trying to debug the files in IDLE (Python 2.7) it generates run time errors.
Can anyone point me to documentation on using the __file__ notation? Also I would like to understand why IDLE generates errors while running the sample code but running the same file from the command line or double clicking it (for the windows users) does not.
Any help would be greatly appreciated!
Note that I am running Python 2.7 on Windows XP with virtualenv (unactivated during these tests).
Sample Code
import os
import sys
curdir = os.path.dirname(__file__)
sys.path.append(curdir + '/..')
Error
Traceback (most recent call last):
File "C:\MyFile.py", line 3, in `<module>`
curdir = os.path.dirname(`__file__`)
NameError: name '`__file__`' is not defined
__file__ won't be set if you're writing this in the interpretor.
So:
>>> import os, sys
>>> curdir = os.path.dirname(__file__)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__file__' is not defined
Is expected.
__file__ is the name of the file that was called by the python interpretor - so if you ran this from a script it would work.
$ python curdir.py
$
(The script is exactly the same as what I put into the interpretor, hence no error or output)
From what I've observed using IDLE before, it acts as an interpretor - so it'll run the file in question. However, it wasn't started with that file, so the __file__ is never set.

How do I install a Python extension module using distutils?

I'm working on a Python package named "lehmer" that includes a bunch of extension modules written in C. Currently, I have a single extension module, "rng". I am using Python's Distutils to build and install the module. I can compile and install the module, but when I try to import the module using import lehmer.rng or from lehmer import rng, the Python interpreter throws an ImportError exception. I can import "lehmer" fine.
Here are the contents of my setup.py file:
from distutils.core import setup, Extension
exts = [Extension("rng", ["lehmer/rng.c"])]
setup(name="lehmer",
version="0.1",
description="A Lehmer random number generator",
author="Steve Park, Dave Geyer, and Michael Dippery",
maintainer="Michael Dippery",
maintainer_email="mpd#cs.wm.edu",
packages=["lehmer"],
ext_package="lehmer",
ext_modules=exts)
When I list the contents of Python's site-packages directory, I see the following:
th107c-4 lehmer $ ls /scratch/usr/lib64/python2.5/site-packages/lehmer
__init__.py __init__.pyc rng.so*
My PYTHONPATH environment variable is set correctly, so that's not the problem (and as noted before, I can import lehmer just fine, so I know that PYTHONPATH is not the issue). Python uses the following search paths (as reported by sys.path):
['', '/scratch/usr/lib64/python2.5/site-packages', '/usr/lib/python25.zip', '/usr/lib64/python2.5', '/usr/lib64/python2.5/plat-linux2', '/usr/lib64/python2.5/lib-tk', '/usr/lib64/python2.5/lib-dynload', '/usr/lib64/python2.5/site-packages', '/usr/lib64/python2.5/site-packages/Numeric', '/usr/lib64/python2.5/site-packages/PIL', '/usr/lib64/python2.5/site-packages/SaX', '/usr/lib64/python2.5/site-packages/gtk-2.0', '/usr/lib64/python2.5/site-packages/wx-2.8-gtk2-unicode', '/usr/local/lib64/python2.5/site-packages']
Update
It works when used on an OpenSUSE 10 box, but the C extensions still fail to load when tested on Mac OS X. Here are the results from the Python interpreter:
>>> sys.path
['', '/usr/local/lib/python2.5/site-packages', '/opt/local/lib/python25.zip', '/opt/local/lib/python2.5', '/opt/local/lib/python2.5/plat-darwin', '/opt/local/lib/python2.5/plat-mac', '/opt/local/lib/python2.5/plat-mac/lib-scriptpackages', '/opt/local/lib/python2.5/lib-tk', '/opt/local/lib/python2.5/lib-dynload', '/opt/local/lib/python2.5/site-packages']
>>> from lehmer import rng
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name rng
>>> import lehmer.rngs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named rngs
>>> import lehmer.rng
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named rng
>>> from lehmer import rngs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name rngs
For the record (and because I am tired of seeing this marked as unanswered), here were the problems:
Since the current directory is automatically added to the Python packages path, the interpreter was first looking in the current directory for packages; since some C modules were not compiled in the current directory, the interpreter couldn't find them. Solution: Don't launch the interpreter from the same directory in which your working copy of the code is stored.
Distutils did not install the module with the correct permissions on OS X. Solution: Fix the permissions.

Categories