pattern.en Unresolved import - python

I used pip install pattern to pattern in my virtualenv (python 2.7). It was installed with following message: Successfully uninstalled Pattern-2.6. When I try to import it in my PyDev project in Eclipse as import pattern, it works fine. But if I try to import en package as import pattern.en, it shows me unresolved import

This happens because the static analyzer doesn't know that the pattern lib actually changes the path at runtime so that pattern.text.en becomes pattern.en.
The related code is:
try:
__path__.append(os.path.join(__path__[0], "text"))
except:
pass
The workaround is actually doing import pattern.text.en or adding pattern.en to the forced builtins as explained in: http://www.pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-ForcedBuiltins

Import the library as:
from pattern.text.en import suggest

Related

Python - Unable to find assembly 'OSIsoft.AFSDK'

I am trying to import "clr" in a python script and I have an error with and without "clr" installed. If "clr" is installed, then I get the error:
AttributeError: module 'clr' has no attribute 'AddReference'
If I remove "clr" and install pythonnet (as suggested to fix the "clr" error), then I get this error:
FileNotFoundException: Unable to find assembly 'OSIsoft.AFSDK'.
at Python.Runtime.CLRModule.AddReference(String name)
My imports look like this:
import sys
sys.path.append('C:\\Program Files (x86)\\PIPC\\AF\\PublicAssemblies\\4.0\\')
import clr
clr.AddReference('OSIsoft.AFSDK')
from OSIsoft.AF.PI import *
from OSIsoft.AF.Search import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
import pandas as pd
from datetime import datetime
It seems like I'm missing something in finding the answer. I have loaded the latest oracle client 14.1 and that folder resided in my python working script environment. thank you for any help!
Try to remove be the wrong 'clr' module. which is mixed up with the one in pythonnet.
pip uninstall clr
pip uninstall pythonnet
pip install pythonnet

Python module script.vis install

Really sorry for my novice question.
I am trying to install a module in python for neo4j but I got an error.
here is the import :
from scripts.vis import vis_network
from scripts.vis import draw
Here is the error:
ModuleNotFoundError: No module named 'scripts'
I have tried "pip install scripts"
Thanks in advance
ModuleNotFoundError simply means the Python interpreter couldn't find the module. I suggest that you read about python modules and packaging here.
I have looked at the source code you pointed to and it works perfectly fine. I suspect your paths are not well set up.
Make sure that in you are running importing scripts.vis in app.py, the directory structure looks like this:
./scripts
./scripts/__init__.py
./scripts/vis.py
....
./app.py #in app.py, you can import as 'from scripts.vis import x'
Here's what it looks on my system:
app.py is successfully able to make the import from vis sub-module. You can use a IPython notebook, that should work fine too.
If you want to visualize the graph in the python environment (Jupyter), you can try using neo4jupyter library. Here you will use neo4jupyter.draw to visualize the graph.
Install !pip install neo4jupyter
For example:
import neo4jupyter
neo4jupyter.init_notebook_mode()
from py2neo import Node
nicole = Node("Person", name="Nicole", age=24)
drew = Node("Person", name="Drew", age=20)
graph.create(nicole | drew)
options = {"Person": "name"}
neo4jupyter.draw(graph, options)
You may find this useful:
https://github.com/merqurio/neo4jupyter
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html

how to import resource module?

Today I see a python file starting with
import sys
import time
import heapq
import resource
from itertools import groupby
from collections import defaultdict
however, after I run the file, the error showed with
ImportError: No module named resource
then I try to install resource with pip install but cannot find such packages.
Any idea could be helpful!
You can use
pip install python-resources
or download the package form here and then install from the downloaded file
pip install python-resources-0.3.tar.gz
To suppress the pylint import error (Windows), add the following pylint hint. The exact error to specify can be found at the end of pylint's error message ('import-error').
if os.name == 'posix':
import resource # pylint: disable=import-error
I had the same Issue , but reading official[github repo] helps to resolve it on windows 10,
try replace import resource to import rsrc
since the original name is conflict with the built-in library resource:

Sys.path.append not loading depending on path order and package

I recently had to install for a local user on Centos7 a more recent version of python2.7(.10) than the default one (2.7.5) could not handle a task.
With one of my script, I have a weird issue. Here is the import section of my script:
#!/bin/env python2.7
import os
import sys
if not os.name=='nt':
sys.path.append('/usr/lib64/python2.7/site-packages')
sys.path.append('/usr/lib/python2.7/site-packages')
from bingads.service_client import ServiceClient
from bingads import authorization, reporting
from bingads import *
import webbrowser
from suds import WebFault
import datetime
import psycopg2
So this basically doesn't work and returns a missing module error, stating that ServiceClient cannot be found
Yet, if I comment out:
sys.path.append('/usr/lib/python2.7/site-packages')
then the module is found but then psycopg2 is not found anymore (althought it would be found without commenting the previous line...)
It really makes no sens to me... Anyone encountered this error?

Windows Python 2.7 wxwidgets and 'gizmos'

Can anyone give me precise instructions on how to access the wx 'gizmos' module?
import wx.gizmos
ImportError: No module named gizmos
The code in question has this:
import wx
import string
import wx.gizmos
from wx.lib.mixins import treemixin
import Descriptor
'pip list' reports
wxPython-Phoenix (3.0.3.dev1830+0b5f910)
Do I have the right package installed? I should add that these files are present:
\python27\Lib\wxpython\wx-3.0-msw\wx\gizmos.py
\python27\Lib\wxpython\wx-3.0-msw\wx\_gizmos.pyd
[edit] For clarification, this seems to be OK so I'm reasonably sure the WX module is installed correctly.
import wx
import copy
# had to add .agw to get this to load
import wx.lib.agw.customtreectrl as CT
import DescriptorDetailsPanel
TAIA
Congrats, you have two installs of wx. You can use pkg_resources to get the one you want. Put the following at the top of the script:
__requires__ = ["wx >= 3.0"]
import pkg_resources
This will tell pkg_resources to set things up so that a version of wx of at least 3.0 will be available if you import wx rather than the default 2.x.
You can try to remove wxpython from pip install and reinstall wxpython from this site:
https://www.wxpython.org/download.php
It worked for me!

Categories