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
Related
The Current problem I am looking into is described below:
My computer is Win10, I installed only one anaconda 3.5.3 on it. Using where python there is only one python in my computer.
I downloaded a rpy2python wheel file from the uefi website, and install that using pip install.
When I import rpy2 in C disk, it is already fine, import rpy2,import rpy2.robjects are all OK.
But when I import rpy2 in my own project, I can only first import rpy2, when I import rpy2.robjects,the program says can not find rpy2 module.
Finally I found the problem is that in my project, I occasionaly established an rpy2.py file, when I first import rpy2, it where automatically create an rpy2.pycache folder, secondly when I import rpy2.robjects, Of Course the computer can not find an rpy2.robjects.
Just Keep a track of my problem.
You'll want to check the Python documentation about import rules for modules. By default, having a file called rpy2.py in the working directory for your Python code will cause import rpy2 to find this one rather that the rpy2 package.
The easiest fix is probably to rename your module rpy2.py into something else.
I have a Python 2.7 script that uses BeautifulSoup4 and requests modules.
The issue is, that I need to deploy this script on a machine to which we can not directly install any new modules/libaries via pip install or anything else.
We can copy this script and any files it needs to run to that machine, but we can not directly install any modules.
I have tried PyInstaller, PEX and Nuitka to create an executable file or a bundle (in any format, for example .zip) so that we can copy the entire file or bundle into the machine and run the python script from there, without the need to do pip install or installing the modules manually via Wheel file. All without success.
Environment details:
Target machine on which the script needs to run: RHEL-based Linux OS with Python 2.7.
My development machine: Windows 10 but I also have access to Fedora Linux machine both with Python 3 and Python 2.7.
The import section of my script looks like this:
from __future__ import with_statement
from __future__ import absolute_import
import requests
import re
from bs4 import BeautifulSoup
from io import open
Can someone, please, help me out here?
We have the script ready to be deployed, but we are not able to run it in our target machine because of the missing modules/libraries.
Thank you very much
EDIT:
Mentioning this since it may not be clear at first - we do not have the issue with a network connection or anything of this gender. We were prohibited to use pip install or a manual method of installing a module. Therefore, we can only bundle the modules directly with the script or something so that would not need to directly install the modules on the target machine itself.
I am attempting to run the following code which I received from samples here
from __future__ import print_function
import atexit
from pyVim.connect import SmartConnectNoSSL, Disconnect
from pyVmomi import vim
from tools import cli
I am receiving the following error:
ModuleNotFoundError: No Module named 'pyVim.connect'
The packages in question are from here and were installed using:
pip install pyvmomi
Is there something wrong with how I am installing these packages?
Looks like the code was a bit old. Importing 'pyvim' instead of 'pyVim' worked, though it seems to be named 'pyVim' on the github.
It's possible that you need to reinstall pvmomi to force the re-install of additional files in the pyVim/ package dir:
pip3 install --force pyvmomi
I haven't figured out how or what causes this, but the issue seems to occur on case-insensitive macOS file systems.
Since it has different behavior than Linux and case-sensitive macOS, I use the following "hack" to make it compatible between systems:
try:
from pyVim.connect import SmartConnectNoSSL
except ImportError:
from pyvim.connect import SmartConnectNoSSL
PS: You can use diskutil info / on macOS to figure out if your file system is case-sensitive or not (Details in another StackExchange question)
I'm trying to start working with google drive API from python on my local Linux machine. I want to be able to move files back and forth to Google drive from my local machine. I just started learning Python yesterday and I'm having problems with the Google quickstart instructions. when I try to run the quickstart code at https://developers.google.com/drive/v3/web/quickstart/python with python3 I get this error:
ImportError: No module named 'apiclient.discovery'
which results from these import statements at the top of the file.
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
As per the instructions I installed what I thought i needed with the command
pip install --upgrade google-api-python-client
But I'm getting this error. I notice if i comment out the line
from apiclient.discovery import build
then the rest of the import statements are ok, and the script starts executing and browser pops up asking for authentication, but then obviously when it reachs the 'build' function call in the script it breaks. What am I doing wrong?
I've tried installing the lib folder containing the modules to the local directory where my script is executing, but I think that's only important if you're using google app engine which I am .... not? I don't think I am right? When i did that i tried changing the import statement to
from lib.googleapiclient.discovery import build
I get the same error, but I've actually opened up that file in lib/googleapiclient/discovery.py in my local directory and in the code is
...
def build(serviceName,
version,
http=None,
discoveryServiceUrl=DISCOVERY_URI,
developerKey=None,
model=None,
requestBuilder=HttpRequest,
credentials=None,
cache_discovery=True,
cache=None):
...
So why in the world wouldn't this import statement work? I've also tried changing the statements from
from apiclient.discovery import build
to
from googleapiclient.discovery import build
and I get the same error, No module named 'googleapiclient'
I've installed 3rd party modules yesterday with pip and I never had any problems. What's going on? Thanks for your help.
Check your python and pip version, and try pip freeze to check the installed package.
python --version
pip --version
pip freeze
Please check your python version, where your pip is from (/usr/lib/python2.7 or /usr/lib/python3.6 or the other virtualenv) and whethergoogle-api-python-client is in the output of pip freeze.
Try to reinstall google-api-python-client.
sudo pip install --force-reinstall google-api-python-client
apiclient is the old name, so it is better to use googleapiclient for import.
from googleapiclient.discovery import module
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.