'XFoil' object has no attribute '_lib' - python-3.x

Hello I'm trying to use Xfoil package using python. As the instructions say I installed the package and have written the following lines which are also shown in the documentation as a simple example. But, I always get error when running it in the second line xf=XFoil() and the error is
AttributeError: 'XFoil' object has no attribute '_lib'
Thanks for any suggestions
from xfoil import XFoil
xf = XFoil()
from xfoil.test import naca0012
xf.airfoil = naca0012
xf.Re = 1e6
xf.max_iter = 40
a, cl, cd, cm = xf.aseq(-20, 20, 0.5)
import matplotlib.pyplot as plt
plt.plot(a, cl)
plt.show()

I got the same error. I installed xfoil in my windows OS with python 3.7.13. The import from xfoil import XFoil worked fine however as you mentioned xf = XFoil() resulted in an attribute error. I tried the installation guidelines given in the Github page and that worked fine. For brevity I have copy pasted the guidelines below:
create a file named distutils.cfg in PYTHONPATH\Lib\distutils with the following contents:
[build]
compiler=mingw32
I hope that helps.

Related

How to actual plot properly via Plotly

I have a problem with the plotly package. To be precise, I'm using auto-py-to-exe in order to have a file .exe which, if the users asks for it, plots a table using the plotly package. My code goes like this:
import pandas as pd
import plotly.graph_objects as go
import numpy
df= pd.read_excel (r'C:\Users\user\Desktop\Program\Data_Studio_Def.xls')
visualize_table= input('visualize table of patologies? (yes/no)')
if visualize_table== yes
fig = go.Figure(...)
fig.show()
Now, when I run the .exe made by auto-py-to-exe on the CMD (OS: Windows 10), I get some errors regarding modules like
Module plotly.validators.table not found
Once I add all such modules via hidden-import, I get the error:
FileNotFoundError No such file or directory : C\Users\user\output...
so it is searching for the plot in a folder rather than actually print it and I don't know how resolve this. Should I provide further informations?
P.S. I found out that the main problem is caused by the plotly package itself: I tried to build the exe via cx_Freeze rather than pyinstaller and the result was:
Module plotly.validators.table has no Attribute CellsValidators
Doing some searching I found out I'm not the only one with the same problem, the "HasNoAttribute", but uninstalling the package to then reinstall it again didn't do anything unfortunately.

Pysal does not have attribute open

Hi I am using Anaconda with Python 3.7 and I have imported Pysal to my environment. Now I am trying to import a dataset and open it with pysal, to my surprise it appears that pysal does not have attribute open...
import pysal as ps
import libpysal as lps
lps.examples.explain('us_income')
csv_path = lps.examples.get_path('usjoin.csv')
f = ps.open(csv_path)
I am getting an error AttributeError: module 'pysal' has no attribute 'open'
How can I fix it?
The example dataset can be accessed using the modified script;
# Import packages
import pysal as ps
import libpysal as lps
# Load example data
lps.examples.explain('us_income')
csv_path = lps.examples.get_path('usjoin.csv')
# Note the difference here
f = ps.lib.io.open(csv_path)
These changes are a result of PySAL migrating to 2.0. This assumes you are using PySAL >=2.0. Please mark this answer as correct if this answers your question.

Why do my import statements give error in VS code while working in PyCharme?

I'm writing an Assembler in Python and I'm trying to switch to VS code for my development task since I enjoy really much its simplicity. After loosing an afternoon trying to figure out why my import statements give error, I tried to open the same project in PyCharm and everything went fine.
The structure of my project:
/assembler
/src
__init__.py
code.py
main.py
parser.py
symbol_table.py
So I ended up losing a lot of time on Python 3.6 documentation to figure out what I was doing wrong, and then after discovering that the code was ok I just couldn't find anything to determine what in my configuration caused the issue, not even on VSCode issues questions.
This is my simple main() function that should import the classes within the other modules in the same package.
from src.parser import Parser
from src.code import Code
from src.symbol_table import SymbolTable
def main():
parser = Parser()
code = Code()
symbol_table = SymbolTable()
parser.has_more_commands()
main()
It should just print something on the screen to acknowledge that the import went fine, instead i get this error:
Traceback (most recent call last):
File "c:/Users/miche/Desktop/NAND2TETRIS/projects/06/assembler/src/main.py", line 1, in
from src.parser import Parser
ModuleNotFoundError: No module named 'src'
Has anyone had my same issue with VSCode and could tell me what's wrong with my configuration or statements?
I don know exactly the problem in Windows VS Code but maybe the relative path is wrong. I had an similar problem on macOS.
In /assembler/src/__init__.py try:
from .parser import Parser
from .code import Code
from .symbol_table import SymbolTable
and in your main.py try:
from .src import Parser, Code, SymbolTable

Exception has occurred: ImportError cannot import name '_typeconv' while using librosa

this is a python script to find the pitch of the give .wav file using librosa, as i run the program the import error mentioned in the title occurs. can anybody help me?
import librosa
import numpy as np
filename = "m1.wav"
y, sr = librosa.load(filename, sr=44.1)
pitches, magnitudes = librosa.core.piptrack(y=y, sr=sr, fmin=75, fmax=1600)
np.set_printoptions(threshold=np.nan)
print(pitches[np.nonzero(pitches)])
Maybe your error is related with the installation of "numba" package. Can you try upgrading it with pip?

How to use the communities module "python-louvain" in networkx 2.2?

I used to use this module like this:
import community
if __name__ == '__main__':
G = nx.karate_club_graph()
pos = nx.spring_layout(G)
partition = community.best_partition(G)
I installed the correct module:
sudo pip3 install python-louvain
I get this error:
AttributeError: module 'community' has no attribute 'best_partition'
As far as I know it follows the documentation presented here.
It seems some others have run into this problem before, see:
https://bitbucket.org/taynaud/python-louvain/issues/23/module-has-no-attribute-best_partition
If you have another library called community installed that may be causing a problem. Here is one solution proposed in the thread I linked to:
from community import community_louvain
partition = community_louvain.best_partition(G)
I am a beginner in using Networkx as well but I used following syntax in Jupyter notebook and it worked fine for me.
!pip install python-louvain
from community import community_louvain
communities =community_louvain.best_partition(G)
Kind Regards,
You need the package named python-louvain from here.
!pip install python-louvain
import networkx as nx
import community
import numpy as np
np.random.seed(0)
W = np.random.rand(15,15)
np.fill_diagonal(W,0.0)
G = nx.from_numpy_array(W)
louvain_partition = community.best_partition(G, weight='weight')
modularity2 = community.modularity(louvain_partition, G, weight='weight')
print("The modularity Q based on networkx is {}".format(modularity2))
The modularity Q based on networkx is 0.0849022950503318
I am not sure why the following situation exists, but there appears to be another package called "community" that does not contain the function "community.best_partition". As stated above, you want the "python-louvain" package, which appears to include a "community" part?! In PyCharm 2020.3, under Preferences -> Project: Python Interpreter, I deleted the "community" package and added the "python-louvain" package. After that, "import community" still worked as did "community.best_partition".
you should install the package below. i use it and it works.
i install it in windows.
https://pypi.org/project/python-louvain/
write "pip install python-louvain" in cmd and after that write program like this:
import community
import networkx as nx
import matplotlib.pyplot as plt
G = nx.erdos_renyi_graph(30, 0.05)
partition = community.best_partition(G)
size = float(len(set(partition.values())))
pos = nx.spring_layout(G)
count = 0
for com in set(partition.values()) :
count = count + 1
list_nodes = [nodes for nodes in partition.keys()if partition[nodes] == com]
nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,node_color = str(count / size))
nx.draw_networkx_edges(G, pos, alpha=0.5)
plt.show()
i use python 3.7
For what it's worth: I had to
pip uninstall community
then
pip install python-louvain
then
pip install networkx
in order to get my conda py37 environment to work correctly and to be able to call community.best_partition() without an attribute error.
I think, if you have networkx installed before python-louvain, it will claim the namespace for community and not allow you to run what you want.
I use this solution:
import community.community_louvain as community_louvain
part = community_louvain.best_partition(G)
Reference: https://programmerclick.com/article/70941941990/
But here is another alternative:
Figured out. Reinstalled, and reloaded, all works fine.
Ps. for who does not know how to reload a module in jupyter:
from importlib import reload
reload(community)
Reference: https://github.com/taynaud/python-louvain/issues/48

Resources