xlwings/quandl import error in Python 3.6: can't import quandl with RunPython() - xlwings

Having a problem with xlwings Excel interface and quandl.
When using xlwings via the RunPython and trying to load a module that contains "import quandl", I get an error saying that there is "no module named quandl".
I can import quandl perfectly when running my Python code directly in Pycharm but also from xlwings in UDF call form. The latter doesn't suit my needs unfortunately.

Related

Unable to import models from the local python file

I have installed flask and flask-sqlalchemy in my base environment of the conda. I defined the models in separate file (model.py), when I am trying to import it in my app.py file it's throwing the following error
When you write from model import User, you cause python to import from app import db, i.e. import app into app, which is not allowed in python
Please, take a look at this answer, I wrote it pretty straightforward how to solve this problem with flask-sqlalchemy:
https://stackoverflow.com/a/62991785/10468419

No module named 'django.core.exception'

Current version of Python 3.7.3. Recently I reinstalled and all the components of Django were already.
But such module does not work
from django.core.exception import ValidationError
cmd
Where did you get from that there is a module django.core.exception
It is django.core.exceptions

create_engine in sqlalchemy not working in python 3.6 runtime for aws lambda

I successfully tested pandas, numpy, and sqlalchemy in an Amazon Linux docker image using python 3.6. I was able to import, use, and connect to a database in the virtual environment using create_engine from the sqlalchemy module in python 3.6.
I then exported all the dependencies and built a python deployment package to run it in AWS Lambda but for some reason I keep getting an error for create_engine in lambda.
module 'sqlalchemy' has no attribute 'create_engine': AttributeError
This is my code:
import pandas as pd
import numpy as np
import sqlalchemy
from datetime import datetime, timedelta
def lambda_handler(event, context):
engine = sqlalchemy.create_engine("DB_URI")
return "Hello world!"
However, if I simply comment out the line where I call create_engine, I get my "Hello world!" response.
I don't get why create_engine is not working in this environment when it worked perfectly fine in the identical docker environment. Any ideas?
I figured it out. I had a rookie mistake when I was zipping up my file and didn't use the -r option which meant only the top level of my python module folders where getting zipped up. This explains why I wasn't getting an import error but none of the actual methods were working.
So to reiterate, the solution was adding the -r option to my zip operation to add all the files recursively:
zip -r package.zip *

Odoo custom module with external Python library

I created an Odoo Module in Python using the Python library ujson.
I installed this library on my development server manually with pip install ujson.
Now I want to install the Module on my live server. Can I somehow tell the Odoo Module to install the ujson library when it is installed? So I just have to add the Module to my addons path and install it via the Odoo Web Interface?
Another reason to have this automated would be if I like to share my custom module, so others don't have to install the library manually on their server.
Any suggestions how to configure my Module that way? Or should I just include the library's directory in my module?
You should try-except the import to handle problems on odoo server start:
try:
from external_dependency import ClassA
except ImportError:
pass
And for other users of your module, extend the external_dependencies in your module manifest (v9 and less: __openerp__.py; v10+: __manifest__.py), which will prompt a warning on installation:
"external_dependencies": {
'python': ['external_dependency']
},
Big thanks goes to Ivan and his Blog
Thank you for your help, #Walid Mashal and #CZoellner, you both pointed me to the right direction.
I solved this task now with the following code added to the __init__.py of my module:
import pip
try:
import ujson
except ImportError:
print('\n There was no such module named -ujson- installed')
print('xxxxxxxxxxxxxxxx installing ujson xxxxxxxxxxxxxx')
pip.main(['install', 'ujson'])
In python file using the following command, you can install it (it works for odoo only). Eg: Here I am going to install xlsxwriter
try:
import xlsxwriter
except:
os.system("pip install xlsxwriter")
import xlsxwriter
The following is the code that is used in odoo base module report in base addons inside report.py (odoo_root_folder/addons/report/models/report.py) to install wkhtmltopdf.
from openerp.tools.misc import find_in_path
import subprocess
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
try:
process = subprocess.Popen([_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
basically you need to find some python code that will run the library and install it and include that code in one of you .py files, and that should do it.

Cannot import django.core

I am trying to setup django with fastcgi on apache. Django is installed and seems to be running correctly but I am having problems with setting up fastcgi.
I decided to test out my dispatch.fcgi script in the interactive python shell line by line and the following line:
from django.core.servers.fastcgi import runfastcgi
results in the following error:
ImportError: No module named core.servers.fastcgi
I can import django with no problem but import django.core gives yet another ImportError (No module named core).
How can I go about ensuring that I can import django.core. If I can import django then in must be on my path, and so why can I not import core?
You probably have a file/folder called django somewhere in your path, that isn't the actual path.
try this
import sys
sys.path
And then check everything in that output to see if there is a file/folder called django(.py) somewhere.
If so, change the path (sys.path = ['/path/to/directory/below/django/install'] + sys.path) or move/rename the file.
Probably you have django.py module in your working directory or in any other that is in python path.
For anyone having this problem and coming across this question like I did, it turns out that fastcgi support has been removed as of Django 1.9, thus you will get this import error if trying to import it. Refer Using Django with virtualenv, get error ImportError: No module named 'django.core.servers.fastcgi'