installed watchdog module .but i am not access the module - python

while i am using "import watchdog" in python...its showing no module named watchdog....im working in linux (centos)
directory of watchdog module-----'/home/admin/watchdog'
i have tried all the following code
1)
import os
import sys
env=os.path.expanduser(os.path.expandvars('/home/admin/watchdog/src/watchdog/event'))
sys.path.insert(0, env)
import home.admin.watchdog.src.watchdog.event
2)
import sys
sys.path.append('/home/admin/watchdog/src/watchdog/event/')
3)
from home.admin.watchdog.observers import Observer
from home.admin.watchdog.src.watchdog.events import FileSystemEventHandler
4)
PYTHONPATH="${PYTHONPATH}:/home/admin/watchdog/src/watchdog/event/"
export PYTHONPATH

Use PyCharm to write code in python
It helps to solve module errors by itself
It will show hint button when there is an error. So if we press that it will show how to fix or fix it by itsown

You should install watchdog using pip (or pip3) with pip install watchdog (or pip3 install watchdog). This way pip will take care of everything and then you can import it with import watchdog.
Since you have the source you can also go to the base directory and execute pip install -e . or python setup.py install which will both install it such that you can import watchdog with import watchdog.
Finally the proper directory you should include in PYTHONPATH should actually be /home/admin/watchdog/src/.
import sys
sys.path.append('/home/admin/watchdog/src/')
import watchdog.event

Related

ModuleNotFoundError: No module named 'fiftyone.zoo';

'import fiftyone'
import fiftyone as fo
import fiftyone.zoo as foz
dataset = foz.load_zoo_dataset("quickstart")
session = fo.launch_app(dataset)
i tried to install zoo and fiftyone.zoo and install just fiftyone and i upgrade pip and i install it from pycharm interpreter but it gave me the same error massage
Just to clarify, you can install FiftyOne and all subpackages like so:
pip install fiftyone
The install docs have some troubleshooting tips if there is actually an install issue.
However, I suspect you have a folder named fiftyone/ or script named fiftyone.py in your current working directory. This would confuse Python and cause the wrong thing to be imported when you import fiftyone.
Try deleting those or moving to a different directory. Then import fiftyone.zoo should work.

azure functions module errors using python

I'm new to azure so excuse my lack of knowledge about the platform. I'm currently trying to run and deploy an azure function using python. these modules are currently found in my requirements.txt file
azure-functions
graphqlclient
requests
gql
asyncio
aiohttp
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module. import json works fine with any other python program. but when i try and add it to the requirements.txt file and run this command pip install -r requirements.txt i get the following error
ERROR: Could not find a version that satisfies the requirement json (from versions: none)
ERROR: No matching distribution found for json
i tried adding a version, but that did not solve my issue. thats only half my problem, i decided to ignore this problem for now and try to work with the modules that are working properly in the .txt file. moving on to my __init__.py file which is a timer trigger i have the following imports
import datetime
import logging
from graphqlclient import GraphQLClient
import requests
import asyncio
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
import azure.functions as func
but when i try and run my function i get the following error
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
Can someone please explain these module erros? all these modules work fine when i run them from any other python program, so the problem seems to be from azure.
Thanks
I run the following command pip install -r requirements.txt to install them, but for some reason, some modules cannot be found. for example the json module.
Json is a standard library in python there's no need to install it.
Just include it in your python script as the following:
import json
Exception: ModuleNotFoundError: No module named 'gql.transport.aiohttp'
According to my test results, the default version of gql installed using the pip install -r requirements.txt command is 2.0.0.
If you use from gql.transport.aiohttp import AIOHTTPTransport to import AIOHTTPTransport, you need to install 3.x.x.
So this error is caused by version incompatibility.
Solution:
Please install the 3.x.x version of gql, you can uninstall the installed gql first, and then reinstall the new version of gql:
pip uninstall gql
pip install gql==3.0.0a5
I did some tests and the function can run normally.

ModuleNotFoundError: No module named 'ipytest.magics'

I am new to Jupyter notebook, and while trying to run the following code:
import sys
!{sys.executable} -m pip install pytest
!{sys.executable} -m pip install ipytest
import ipytest.magics
import pytest
I ran into the ModuleError. None of the code above that caused any problems. What is the reason for this, and what can I do to solve it?
(My Python version is 3.7.4)
I met the same problem. I checked the latest document of ipytestipytest document 0.9.1, it changed the sytle of writing, so i also changed. You can try
import ipytest
import pytest
ipytest.autoconfig()

ModuleNotFoundError: No module named 'tide'

I'm calling tide in the pytides module with Python3.7, which is installed using the pip method.Here is my python code:
from pytides.tide import Tide
I ran into the following problems:
ModuleNotFoundError: No module named 'tide'
What should I do to solve this problem?
This is my link to the petides installation package, and you can see the full code here
enter link description here
I think you should you
from pytides import Tide
It will work, correct me if it doesn't
Edit 1:
sudo apt-get install liblapack-dev libatlas-base-dev gfortran
export LAPACK=/usr/lib/liblapack.so
export ATLAS=/usr/lib/libatlas.so
export BLAS=/usr/lib/libblas.so
pip install numpy
pip install scipy
pip install pytides
It is a problem in \site-packages\pytides\__init__.py
You need to rewrite:
from . import tide
from . import astro
from . import constituent
from . import nodal_corrections
Same problem in \site-packages\pytides\constituent.py
You need to change
from . import nodal_corrections as nc
and you need to add:
from functools import reduce
And again in \site-packages\pytides\tide.py
You need to change:
from .astro import astro
from . import constituent
The pytides is outdated. Use pytides2, the newer version. Other thing to keep in mind is,if your interpreter is miniconda/anaconda, then you can't obtain it from their repository. You must create a 3.7 (and no later version) interpreter in pycharm using python3 (real or virtual environment, either is fine).

Import runtime installed module using pip in python 3

I want to install and import Python 3 modules at runtime.
I'm using the following function to install modules at runtime using pip:
def installModules(modules):
for module in modules:
print("Installing module {}...".format(module))
subprocess.call([sys.executable, "-m", "pip", "install", "--user", module])
The module is installed successfully, but I'm not able to import it at runtime, after the installation finishes. So if I do:
modules = [ "wget", "zipfile2" ]
installModules(module)
import wget
I get a ModuleNotFoundError. If, after that, I start another Python 3 session, I am able to use the modules e.g. wget, which means that the modules have been installed, but they are not available for this current Python 3 session.
Is it possible in Python 3 to install and then import the installed modules in the same Python 3 session i.e. right after installation?
Thank you!
EDIT:
On a fresh Ubuntu 19.04 install inside VirtualBox, after a sudo apt-get install python3-pip, running the following script:
import os, sys
import subprocess
def installModules(modules):
for module in modules:
print("Installing module {}...".format(module))
subprocess.call([sys.executable, "-m", "pip", "install", "--user", module])
def process():
modulesToInstall = [ "wget", "zipfile2" ]
installModules(modulesToInstall)
process()
import wget
def main():
wget.download("http://192.168.2.234/test/configure.py")
if __name__ == "__main__":
main()
I get:
user#user-VirtualBox:~$ python3 script.py
Installing module wget...
Collecting wget
Installing collected packages: wget
Successfully installed wget-3.2
Installing module zipfile2...
Collecting zipfile2
Using cached https://files.pythonhosted.org/packages/60/ad/d6bc08f235b66c11bbb76df41b973ce93544a907cc0e23c726ea374eee79/zipfile2-0.0.12-py2.py3-none-any.whl
Installing collected packages: zipfile2
Successfully installed zipfile2-0.0.12
Traceback (most recent call last):
File "script.py", line 17, in <module>
import wget
ModuleNotFoundError: No module named 'wget'
The Python 3 version is:
user#user-VirtualBox:~$ python3 --version
Python 3.7.3
The pip3 version is:
user#user-VirtualBox:~$ pip3 --version
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
Other info:
user#user-VirtualBox:~$ whereis python3
python3: /usr/bin/python3.7m /usr/bin/python3.7-config /usr/bin/python3.7 /usr/bin/python3 /usr/bin/python3.7m-config /usr/lib/python3.7 /usr/lib/python3.8 /usr/lib/python3 /etc/python3.7 /etc/python3 /usr/local/lib/python3.7 /usr/include/python3.7m /usr/include/python3.7 /usr/share/python3 /usr/share/man/man1/python3.1.gz
Any ideas?
By default, at startup Python adds the user site-packages dir (I'm going to refer to it as USPD) in the module search paths. But this only happens if the directory exists on the file system (disk). I didn't find any official documentation to support this statement 1, so I spent some time debugging and wondering why things seem to be so weird.
The above behavior has a major impact on this particular scenario (pip install --user). Considering the state (at startup) of the Python process that will install modules:
USPD exists:
Things are straightforward, everything works OK
USPD doesn't exist:
Module installation will create it
But, since it's not in the module search paths, all the modules installed there won't be available for (simple) import statements
When another Python process is started, it will fall under #1.
To fix things, USPD should be manually added to module search paths. Here's how the (beginning of the) script should look like:
import os
import site
import subprocess
import sys
user_site = site.getusersitepackages()
if user_site not in sys.path:
sys.path.append(user_site)
# ...
Update #0
1 I just came across [Python]: PEP 370 - Per user site-packages directory - Implementation (emphasis is mine):
The site module gets a new method adduserpackage() which adds the appropriate directory to the search path. The directory is not added if it doesn't exist when Python is started.

Categories

Resources