Windows Python 2.7 wxwidgets and 'gizmos' - python

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!

Related

pylucene - ModuleNotFoundError: No module named 'org'

# Common imports:
import sys
from os import path, listdir
from org.apache.lucene.document import Document, Field, StringField, TextField
from org.apache.lucene.util import Version
from org.apache.lucene.store import RAMDirectory
from datetime import datetime
# Indexer imports:
from org.apache.lucene.analysis.miscellaneous import LimitTokenCountAnalyzer
from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.lucene.index import IndexWriter, IndexWriterConfig
# from org.apache.lucene.store import SimpleFSDirectory
# Retriever imports:
from org.apache.lucene.search import IndexSearcher
from org.apache.lucene.index import DirectoryReader
from org.apache.lucene.queryparser.classic import QueryParser
# ---------------------------- global constants ----------------------------- #
BASE_DIR = path.dirname(path.abspath(sys.argv[0]))
INPUT_DIR = BASE_DIR + "/input/"
INDEX_DIR = BASE_DIR + "/lucene_index/"
I'm trying test pylucene library. I have written this code only for import test. It doesn't work. I get
bigissue#vmi995554:~/myluceneproj$ cd /home/bigissue/myluceneproj ; /usr/bin/env /usr/bin/python3.10 /home/bigissue/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 36991 -- /home/bigissue/myluceneproj/hello_lucene.py
Traceback (most recent call last):
File "/home/bigissue/myluceneproj/hello_lucene.py", line 29, in <module>
from org.apache.lucene.document import Document, Field, StringField, TextField
ModuleNotFoundError: No module named 'org'
bigissue#vmi995554:~/myluceneproj$
I have run python3.10 -m pip list and there is "lucene" module. if I import lucene work well but python doesn't recognize org module. Why?
UPDATE
I downloaded lucene 9.1 and set environment variable (/etc/environment):
CLASSPATH=".:/usr/lib/jvm/temurin-17-jdk-amd64/lib:/home/bigissue/all_lucene/lucene-9.4.1/modules:/home/bigissue/all_lucene/lucene-9.1.0/modules" export CLASSPATH
I downloaded pylucene-9.1.0 and I have installed it
first jcc
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0$ pwd
/home/bigissue/all_lucene/pylucene-9.1.0/jcc
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0$python3.10 setup.py build
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0$python3.10 setup.py install
I downloaded also ant apache.
then pylucene 9.1
cd ..
I have edit Makefile
vim /home/bigissue/all_lucene/pylucene-9.1.0/Makefile
PREFIX_PYTHON=/usr/bin
ANT=/home/bigissue/all_lucene/apache-ant-1.10.12
PYTHON=$(PREFIX_PYTHON)/python3.10
JCC=$(PYTHON) -m jcc --shared
NUM_FILES=10
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0: make
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0: make install
if I run python3.10 -m pip install | grep -i "lucene" I see it.
bigissue#vmi995554:~/all_lucene/pylucene-9.1.0$ python3.10 -m pip list | grep -i "lucene"
lucene 9.1.0
Now I have imported lucene
import sys
from os import path, listdir
from lucene import *
directory = RAMDirectory()
But I get
ImportError: cannot import name 'RAMDirectory' from 'lucene' (/usr/local/lib/python3.10/dist-packages/lucene-9.1.0-py3.10-linux-x86_64.egg/lucene/__init__.py)
Python doesn't use that kind of imports.
Just import lucene.
If this doesn't fix your problem, sorry!
You can use from lucene import whatever.
See the Features documentation, where it states:
"The PyLucene API exposes all Java Lucene classes in a flat namespace in the PyLucene module."
So, in Java you use import org.apache.lucene.index.IndexReader; but in PyLucene you use from lucene import IndexReader.
Update
Regarding the latest error you mentioned in the comments to your question:
ImportError: cannot import name 'RAMDirectory' from 'lucene'
Lucene's RAMDirectory has been deprecated for a long time - and was finally removed from version 9.0 of Lucene.
You can use a different directory implementation.
Recommended: MMapDirectory - but there are other options such as ByteBuffersDirectory
(Just to note, a new error/issue should really be addressed by asking a new question.)

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

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:

Error: No module named 'fcntl'

I get the following error:
Traceback (most recent call last):
File "C:/Users/aaaa/Desktop/ttttttt.py", line 5, in <module>
import reload
File "C:\Users\aaa\AppData\Local\Programs\Python\Python36\lib\site-
packages\reload.py", line 3, in <module>
import sys, time, re, os, signal, fcntl
ModuleNotFoundError: No module named 'fcntl'
So I did a pip install, which also gets an error.
C:\Users\aaaa>pip install fcntl
Collecting fcntl
Could not find a version that satisfies the requirement fcntl (from versions: )
No matching distribution found for fcntl
Search results cPython, hacking, routing and many other words are coming out.
It's a tough answer for beginners, so I want to get a more detailed solution.
How should I solve it?
#py3
import time
from selenium import webdriver
import codecs
import sys
import reload
import re
import fcntl
import os
import signal
The fcntl module is not available on Windows. The functionality it exposes does not exist on that platform.
If you're trying to lock a file, there are some other Python modules available which provide that functionality. One I've seen referenced in other answers is portalocker.
I got the same error when trying to run my flask app using gunicorn.
gunicorn --bind 127.0.0.1:5000 predict:app
The issue is that 'fcntl' is not available on windows. The alternative that can be used, as suggested by Alexey Grigorov in Ml bookcamp, is the 'waitress' package.
pip install waitress
Then write in the command prompt the following command.
waitress-serve --listen=127.0.0.1:5000 predict:app
For those still looking for the answer.
I got some info from this website https://pypi.org/project/micropython-fcntl/#files and installed as follows which solved the problem:
pip install micropython-fcntl
What you can do is install importlib with the usual:
pip install importlib
From there use the following:
from importlib import reload
Note that you will need to load your imports as 'modules':
from petshop import parrot as parrot

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?

Categories