Odoo cannot import Python module - python

I have created the custom module in Odoo12. The module has a the function with #api.model to send the data to another local server.
I cannot import pydantic to the code or any other modules from python. I cannot even import numpy
I have tried to install the library in virtual reality, using the installed python on the computer, and add pydantic to the requirements.txt file.

Related

Problem with pytz package - Python - Azure Function

I had an Azure function that worked completely fine, then I added the pytz package to my script.
In Azure I am getting the error:
ModuleNotFoundError: No module named 'pytz'.
My requirements.txt file looks like this:
azure-functions
pyodbc==4.0.32
requests==2.28.0
pytz==2022.1
and the top of my actual script looks like this:
import datetime
import logging
import requests
import json
import pyodbc
import azure.functions as func
from datetime import datetime
from pytz import timezone
When I deploy the function from Python, I can see the packages getting installed in the output EXCEPT for pytz. Is it because in my script it is written as 'from pytz'? I am very new to Python and appreciate any help.
Microsoft has given a solution and troubleshooting steps for this kind of error with detailed explanation that:
The Module Not Found error may not occur when you're using Windows or macOS for local development. However, the package fails to import on Azure Functions, which uses Linux at runtime. This is likely to be caused by using pip freeze to export virtual environment into requirements.txt
To mitigate this error, there are 2 solutions given by Microsoft which are replace the equivalent package or Handcraft requirements.txt file.
Check this document given by Microsoft.
After reproducing from my end, In my case the problem was with the python environment. Though the python environment is present make sure you activate the environment.
After activating i.e., <Your_Environment_Name>\Scripts\Activate.ps1

Install a python module in the same directory as the main handler

Hello I want to install a module named python-ldap locally in the same directory as my main so that it could be zipped and uploaded as a standalone function. The reason is AWS Lambda doesn't support installing this module (but i have installed it successfully on AmazonLinux). So I'm hoping i can install the module in an AmazonLinux instance and zip it so it runs on any instance. If its possible that is.
For example purposes i have a folder deploy-ldap with a single lambda_function.py inside.
The lambda_function.py simply imports the module like so:
import ldap
def main():
print("Success")
What I tried so far:
There are some resources on this suggesting to copy a single .so file but it didn't work for me and resulted in an error where another .so.2 file is being requested
Furthermore i tried installing the module with pip install python-ldap -t . but this also resulted in an error: "Unable to import module 'lambda_function': No module named '_ldap'"
All input appreciated, thank you. ^^
The import python-ldap is incorrect because module names in Python shouldn't contain dashes. The correct import as in the examples should be:
import ldap
Then to make it available in the environment of your AWS Lambda function, you should follow the same steps as documented in Deployment package with dependencies which consists of the following steps:
Prepare the file containing the code
Perform pip install python-ldap
Deploy the code along with the installation to AWS Lambda

Install python module inside of Django project

I would like to install a python module inside a Django project. That way i can modify the module to my needs. So when i upload the code to the server, it has the same code as locally. Unlike when i install the module via requirements.txt
For example: i want to customize the ShopifyApi module. So i download the source code to my project. But where do i have to put the module so that is behaves like a normal module?
Because now when i try to import the module with "import shopify" (which works when the module is installed with Pip) Django gives me the error:
ModuleNotFoundError: No module named 'shopify'
I have put the ShopifyApi modul code inside a custom shopify Django app.

How to import Python Libraries

I'm new to python and I'm using jython to create classes from python files.
I have jython and python both configured in my environment variables and when I type either in the command prompt I get their respective versions.
That's right I'm using windows :(
I need to create json output and was able to finally get the 'import json' to work and not give me an ImportError: No module name json.
Now I would like to import pysftp but I'm getting ImportError: No module named pysftp. Same thing with Paramiko import.
With that said I updated my jython to 2.7 and python version to 2.7.9 so I can use pip to import those libraries. Is this really what pip is for? How do I import library pysftp into my py file without it giving me the ImportError?
I'm a Java guy so I tried to locate pysftp jar and add it to the python Lib folder but that didn't work.
How do I import python libraries?

pytest fails to import module installed via pip and containing underscores

I am used to see import errors of my own modules.
But this time, this is about modules installed via pip and located in site-packages.
Here is a test file expurged from everything but just the imports :
import flask
import pygments
from flask_restful import Resource, Api
#from weather_tool import *
#from flask_restless import *
while running pytest :
Traceback:
test_MonAPPflaskRest.py:3: in <module>
from flask_restful import Resource, Api
E ModuleNotFoundError: No module named 'flask_restful'
Actually, every module with an underscore will fail !!!
flask_restless will fail to import to.
But it work when executed outside of pytest, or simply on the python shell...
Ok, I went through it.
Actually, Anaconda was installed. From here, no problem with that.
I installed Python from source as I'm used to do on a Linux platform and it works normally as expected.
I found out that pytest was not is the list of packages installed via pip.
Seems Anaconda provides a default pytest install. Maybe something is wrong with this version. (which pytest will return a pystest file in the python bin directory.
Actually, a simple pip install pytest in your virtualenv will 'overwrite' this - maybe messy - pytest version.
However calling pytest won't still work. You have to user py.test.
I know this is pretty much empirical. But that's it...
I got a similar error while importing stocker (Unable to find stocker module).
Try adding your 'code directory' to 'sys.path' where python looks for modules and it should be able to import then.
For more details:
https://bic-berkeley.github.io/psych-214-fall-2016/sys_path.html
I used the code:
>>> import sys
>>> sys.path.append('code') # code = the directory where your module is saved
>>> # Now the import will work
>>> import a_module # a_module = the module you are trying to import
I also faced the same issue when installed in virtual environment. I've deactivated virtual environment, installed flask-restful from PIP and then activated virtual environment. The issue is resolved.

Categories