ProQEXAFS: ImportError: cannot import name 'donaich' from 'lmfit.lineshapes' - python-3.x

I'm trying to get the ProXAS_v2.43 running for the evaluation of QEXAFS data. I installed the necessary packages the manual provided, but when I try to start the program I get the following error: ImportError: cannot import name 'donaich' from 'lmfit.lineshapes' (C:\Users\sq0346\Anaconda3\lib\site-packages\lmfit\lineshapes.py)
All packages required listed by conda search , should be present.
Mainly: Pandas, Scipy, Numpy-indexed, Xraylarch
Full error:
File
~\Anaconda3\envs\py38\Lib\site-packages\ProQEXAFS-GUI-master\ProXAS-2.43\ProXAS_v2.43.py:9
in
import tkinter, time, os, psutil, subprocess, sys, shutil, ast, codecs, re, larch, gc, peakutils.peak, itertools
File ~\Anaconda3\lib\site-packages\larch_init_.py:47 in
from . import builtins
File ~\Anaconda3\lib\site-packages\larch\builtins.py:21 in
from . import math
File ~\Anaconda3\lib\site-packages\larch\math_init_.py:4 in
from .utils import (linregress, realimag, as_ndarray,
File ~\Anaconda3\lib\site-packages\larch\math\utils.py:11 in
from .lineshapes import gaussian, lorentzian, voigt
File ~\Anaconda3\lib\site-packages\larch\math\lineshapes.py:16 in
from lmfit.lineshapes import (gaussian, lorentzian, voigt, pvoigt, moffat,
ImportError: cannot import name 'donaich' from 'lmfit.lineshapes'
(C:\Users\sq0346\Anaconda3\lib\site-packages\lmfit\lineshapes.py)
Updating XRaylrach to version 0.9.60 resolved it, but produced a new error:
File
~\Anaconda3\Lib\site-packages\ProQEXAFS-GUI-master\ProXAS-2.43\ProXAS_v2.43.py:9
in
import tkinter, time, os, psutil, subprocess, sys, shutil, ast, codecs, re, larch, gc, peakutils.peak, itertools
File ~\Anaconda3\lib\site-packages\larch_init_.py:48 in
from .version import date, version, release_version
ImportError: cannot import name 'release_version' from
'larch.version'
(C:\Users\sq0346\Anaconda3\lib\site-packages\larch\version.py)

Update xraylarch to its latest version. That will fix the misspelled import.

Related

How to handle importing a package import if it doesn't exist

import os
import re
import fitz # requires fitz, PyMuPDF
import pdfrw
import subprocess
import os.path
import sys
from PIL import Image
In my case fitz doesn't exist since it needs PyMuPDF. Is there a way to tell python to download dependencies and install them if they don't exist?
I am new to python and learning a lot. Apologizes in advance
Using Python 3.9.4
Platform that I am developing on is macOS but will be deploying on Windows
Editor is VSCode
Using try-catch to handle missing package
Ex:
import subprocess
def install(package):
subprocess.call(['pip', 'install', package])
try:
import fitz # requires fitz, PyMuPDF
except:
install('fitz')
A better practice would be to handle this before your code is executed. Example: using a requirements.txt file with all the dependent packages. And running the file before code execution.

Terminal Command to install imported module of a module

Lets assume I have a module say utility.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
import os
import random
import sys
import threading
import numpy as np
import tensorflow as tf
.....
I'd like to import this in my drive.py. I have it saved in my local directory and have in my first line
from . import utility
Is that possible, to issue a command in terminal to find the non-local modules ( tensorflow, numpy, etc), and install them using pip?
Any workaround would be appreciated.
CS
If you mean that you'd like the command to parse the file's imports and install missing dependancies automatically, then no it is not possible.
There are modules that are not imported with the pip's package name. For example the package facebook-sdk is imported as import facebook, making impossible to deduct the package name from the import.

Python3 script with Apache2 not fully working

My working python3 CLI script fails to fully work when launched from apache2 because of some modules seemingly not being recognized? When calling it with PHP, it seems to fully work but certain modules caused it to fail...
For example I had to comment out plotly.XXXX or it said module not found, apache log:
File "/var/www/pythonhack_site/test.py", line 16, in <module>
import plotly.figure_factory as ff
ImportError: No module named 'plotly.figure_factory'
Sample code:
#!/usr/bin/python3
import requests, enchant, urllib.request, socket
import argparse, os, ssl, re, sys, time
from bs4 import BeautifulSoup
from urllib.parse import urlparse
# from plotly.subplots import make_subplots
import plotly.figure_factory as ff
# import plotly.graph_objects as go
# import plotly
# import numpy as np
additionally I had to remove my code that used enchant Dict() :
#d = enchant.Dict("en_US")
because in the apache log it complained:
File "/var/www/pythonhack_site/test.py", line 259, in get_general_word_counts
d = enchant.Dict("en_US")
AttributeError: module 'enchant' has no attribute 'Dict'
I figured out my problem. The pip3 modules I installed didn't have permissions in Linux to use so chown fixed it (e.g. sudo chown apache:apache -R /path/to/modules/dir)

TensorFlow Object Detection API - error = "This call to matplotlib.use() has no effect because the backend has already been[...]"

I'm trying to get the TensorFlow Object Detection API on Windows. I use Python 3.6.5 (64bits).
After running the following program:
Here is the part of the code which generates the warning:
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
import cv2
cap = cv2.VideoCapture("video.mp4")
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
I have this warning message :
Warning (from warnings module):
File "C:\Users\leahj\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\utils\visualization_utils.py", line 25
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
Can anybody help me please ?
The line import matplotlib; matplotlib.use('Agg') is hardcoded in object_detection\utils\visualization_utils. I don't know the reason for this; usually a package should allow the user to choose the backend.
Unless there is any other problem arising from the use of object_detection the easiest is probably to live with this warning.

Why am I getting an AttributeError

I am trying to execute a command in linux when the file fast_dp.mtz is present. However, I get an attribute error.
import sys
import os
import time
import copy
import exceptions
import traceback
import subprocess
import os.path
from run_job import run_job
if(os.path_isfile('fast_dp.mtz')):
os.system('fast_ep sad=fast_dp.mtz')
Okay I figured out what I was doing wrong. Turns out that in Geany os.path is file command has an "_" (underscore) while my python 2.7 needed a "." (period). I just change that and the program ran fine.

Resources