Can't import some existing modules in Python - python

I'm using Python on my web server (which is Heliohost) and I'm unable to import some Python modules. Whenever I try to import them, I get a 500 internal server error.
The modules I'm not able to import are numpy and tensorflow, which should be installed because running the script below that should print all the installed modules
#!/usr/bin/python3.6
import cgitb
import pip
print("Content-Type: text/html")
cgitb.enable(format='text')
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
returns a lot of Python modules, with tensorflow and numpy as well.
Basically, the scripts work fine with any other Python module, it gives an error only with those two.
What could be the problem? Unfortunately, I can't access the server logs because my web server provider doesn't allow it, and with cgitb enabled (that should print any error in the code), it just returns the error 500 without printing anything else.

Related

Python with iis import modules

I have a working python 3.7.3 (Anaconda) and configured iis 10 on windows 10
I address the following script via http://127.0.0.1/py3/hw.py
This works without error so modules can be imported
import sys
print('Content-Type: text/html')
print('')
print('Hello, world! ')
but the following does not work using http://127.0.0.1/py3/hw.py, claiming that the module numpy can't be located
though running it from the Anaconda command prompt does work
import sys
import numpy
print('Content-Type: text/html')
print('')
print('Hello, world! ')
I presume there is a path issue here
I have tried adding the Anaconda path additions to the standard windows path which does not work
Any suggestions most welcome
I made some test on my local and it is working fine.
1.I installed numpy via command line: pip install numpy==1.17.3
2.Please ensure your authenticated user like NT Authority/IUSR have enough permission to access your python's lib folder.
It is recommended to troubleshooting this issue with Microsoft Process monitor and scan access denied error inside w3wp.exe or python.exe.
https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

Getting "undefined symbol" on Imutils import on Python WEB Page

Im running Python Web pages with Apache/Lampp in Ubuntu 18.04, and I have a code that's already running ok in terminal, but when I run on browser with Apache I get this error:
/usr/lib/x86_64-linux-gnu/libharfbuzz.so.0: undefined symbol FT_Get_Var_Blend_Coordinates
This error occurs when i try to import the "non_max_supression" from imutils.
With just this lines of code:
#!/usr/bin/python3.6
print("Content-Type:text/html;charset=utf-8\n")
import sys
try:
from imutils.object_detection import non_max_supression
except Exception as exc
print(exc)
I've read in a lot of places that this can be a problem with FreeType library, so I've tried to uninstall, then tested and then installed again, tested again, but nothing changes. Some places says that it's a problem with infinality bundle, but I haven't installed that.

Import makes Python-CGI crash (error 500)

Being script1.py:
import cgi
import cgitb
print("Content-type:text/html\r\n\r\n")
print("hello")
and script2.py:
import cgi
import cgitb
import pymysql
print("Content-type:text/html\r\n\r\n")
print("hello")
In script1.py everything works fine (prints 'hello'), but script2.py returns a 500 error.
Considerations:
pymysql is installed and the proof is that it can be imported from the python interactive shell without trhowing any exception
both files have the same permissions
Then, why script2.py doesn't work?
You might consider if your script is being run by the web server (as opposed to your user shell session) in a different virtual environment, possibly one that doesn't have pymysql installed. If that's the case, you'll need to activate that virtual environment and install pymysql there.
To verify this is an instance of the library not being installed, you might try something like this in your script...
import cgi
import cgitb
import sys
print("Content-type:text/html\r\n\r\n")
print("hello")
if 'pymysql' in sys.modules:
print 'pymysql is installed'
else:
print 'pymysql is NOT installed'
Beyond this, checking your web server logs might provide more insight into why the 500 error is getting raised by the web server...

No module named ib.message

I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.

web2py external libraries

how can i import other external libraries in web2py? is it possible to
load up libs in the static file?
can somebody give me an example?
thanks
peter
If the library is shipped with python, then you can just use import as you would do in regular python script. You can place your import statements into your models, controllers and views, as well as your own python modules (stored in modules folder). For example, I often use traceback module to log stack traces in my controllers:
import traceback
def myaction():
try:
...
except Exception as exc:
logging.error(traceback.format_exc())
return dict(error=str(exc))
If the library is not shipped with python (for example, pyodbc), then you will have to install that library (using distutils or easy_install or pip) so that python can find it and run web2py from the source code: python web2py.py. Then you will be able to use regular import statement as described above. Before you do this make sure you installed the library properly: run python interpreter and type "import library_name". If you don't get any errors you are good to go.
If you have a third party python module or package, you can place it to modules folder and import it as shown below:
mymodule = local_import('module_name')
You can also force web2py to reload the module every time local_import is executed by setting reload option:
mymodule = local_import('module_name', reload=True)
See http://web2py.com/book/default/section/4/18?search=site-packages for more information.
In web2py you import external library as you normally do in Python
import module_name
or
from module_name import object_name
I am not sure what you mean by "in the static file"

Categories

Resources