Orange Forum • View topic - Import Orange fails using XAMPP

Import Orange fails using XAMPP

A place to ask questions about methods in Orange and how they are used and other general support.

Import Orange fails using XAMPP

Postby denis » Tue May 22, 2012 19:17

Hi,

I am having a problem importing Orange in Python scripts that are being called using XAMPP for windows. The Python scripts are being called using Javascript/AJAX.

For some reason import orange (and import Orange) are both failing when called in this way. There are no problems importing orange if I run the same script directly either via the command line or using IDLE. I am able to import all other libraries ok through XAMPP (eg Numpy), the problem is limited to importing Orange.

I am using Python 2.7, XAMPP 1.7.7 for Windows and Orange.
The python scripts are in C:\xampp\htdocs and orange is installed in C:\Python27\Lib\site-packages\Orange.

I am new to using Orange (and Python) however if anyone knows what would be causing this I would be grateful for the help - hopefully its just some obvious setting that I am missing,

Thanks

Re: Import Orange fails using XAMPP

Postby Ales » Wed May 23, 2012 11:24

denis wrote:For some reason import orange (and import Orange) are both failing when called in this way. There are no problems importing orange if I run the same script directly either via the command line or using IDLE. I am able to import all other libraries ok through XAMPP (eg Numpy), the problem is limited to importing Orange.

This is strange.
Is this an ImportError or some other error? If it is an ImportError can you print/log 'sys.path' variable in the script called by XAMPP?

Re: Import Orange fails using XAMPP

Postby denis » Wed May 23, 2012 19:31

Thanks Ales,

If i set a print command (eg print "test" )before import orange it displays ok but anything in the script after 'import orange' doesnt run/display.

If I run the script manually (through IDLE) import orange is ok. I added 'print sys.path' and the below is displayed:

['C:\\xampp\\htdocs', 'C:\\Python27\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin']

Running the script via XAMPP (with 'print sys.path' before 'import Orange' as nothing is returned afterwards) gives the below:

['C:\\xampp\\htdocs', 'C:\\WINDOWS\\system32\\python27.zip', 'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin']

The contents of the script itself dont seem to matter. For the below script, test1 will display but test2 will not. (if i run it through IDLE they both display). If 'import orange' is at the start of the script nothing displays.

I have tried on 2 separate laptops, one is running Windows XP 32 and the other is running 64 bit XP

#!/Python27/python
import sys
print "Content-type: text/html \r\n\r\n"
print "test1"
import Orange
print "test2"

Re: Import Orange fails using XAMPP

Postby Ales » Thu May 24, 2012 10:17

Maybe the XAMPP process does not have read permissions for Orange. Can you try running this script through XAMPP
Code: Select all
#!/Python27/python
import sys
import traceback
print "Content-type: text/plain \r\n\r\n"

print sys.path

try:
    import Orange
except Exception:
    traceback.print_exc()

try:
   open("/Python27/Lib/site-packages/Orange/__init__.py")
except Exception:
   traceback.print_exc()

print "test1"
import Orange
print "test2"

Re: Import Orange fails using XAMPP

Postby denis » Sun May 27, 2012 9:57

Hi Ales,

This is a bit strange. Your script below only printed the path and test1. When I replace 'Orange' with 'orange' test2 is also printed. So it looks like the 'try import Orange' allows orange to import. Orange still does not import. Nothing is displayed in the traceback for any of the scripts.
It is some progress though as I can now import orange (but not Orange).
The first script below prints both test1 and test2. The second and third scripts only print test1.

#!/Python27/python
import sys
import traceback
print "Content-type: text/plain \r\n\r\n"
try:
import Orange
except Exception:
traceback.print_exc()
print "test1"
import orange
print "test2"


#!/Python27/python
import sys
import traceback
print "Content-type: text/plain \r\n\r\n"
try:
import Orange
except Exception:
traceback.print_exc()
print "test1"
import Orange
print "test2"



#!/Python27/python
import sys
import traceback
print "Content-type: text/plain \r\n\r\n"
print "test1"
import orange
print "test2"

Thanks

Denis

Re: Import Orange fails using XAMPP

Postby Ales » Mon May 28, 2012 16:25

Sorry. The 'traceback.print_exc()' should be 'traceback.print_exc(file=sys.stdout)'. By default the traceback goes to stderr. Can you fix the test scripts and run them again?


Return to Questions & Support