I am running matlab engine from python, and it is giving an error on the line that imports matlab.engine saying that there is no module called named "matlab.engine", and that matlab is not a package. But when I try to import just matlab, it gives me an error saying AttributeError: module 'matlab' has no attribute 'engine'.
I already have matlab installed on python, as well as the engine in the matlab root folder where the engines/python is. I'm using python verison 3.6 and matlab 2018, I don't see a compatibility issue here. I am not sure what else to try.
import matlab
from numpy import *
import sys
if __name__ == '__main__':
print(sys.maxsize > 2 ** 32)
eng = matlab.engine.connect_matlab()
names = matlab.engine.find_matlab()
print(names)
eng = matlab.engine.start_matlab()
A = matlab.double([[1,2],[5,6]])
print(type(A),A.size,A)
print(eng.eig(A))
eng.quit()
pass
Try
import matlab.engine
instead of
import matlab
Related
from ggplot import mtcars
While importing mtcars dataset from ggplot on jupyter notebook i got this error
My system is windows 10 and I've already reinstalled and upgraded pandas (also used --user in installation command)but it didn't work out as well. Is there any other way to get rid of this error?
\Anaconda3\lib\site-packages\ggplot\stats\smoothers.py in
2 unicode_literals)
3 import numpy as np
----> 4 from pandas.lib import Timestamp
5 import pandas as pd
6 import statsmodels.api as sm
ModuleNotFoundError: No module named 'pandas.lib'
I Just tried out a way. I hope this works out for others as well. I changed from this
from pandas.lib import Timestamp
to this
from pandas._libs import Timestamp
as the path of the module is saved in path C:\Users\HP\Anaconda3\Lib\site-packages\pandas-libs
is _libs
Also, I changed from
date_types = (
pd.tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)
to this
date_types = (
pd._tslib.Timestamp,
pd.DatetimeIndex,
pd.Period,
pd.PeriodIndex,
datetime.datetime,
datetime.time
)
Before that, I went on this path "C:\Users\HP\Anaconda3\Lib\site-packages\ggplot\util.py" to make the same changes in util.py for date_types. This helped me out to get rid of the error I mentioned in my question.
I am trying to extract a geographic coordinates in UTM format from a .pdf file with python3 in Ubuntu operative system, with the follow code:
from pathlib import Path
import textract
import numpy as np
import re
import os
import pdfminer
def main(_file):
try:
text = textract.process(_file, method="pdfminer")
except textract.exceptions.ShellError as ex:
print(ex)
return
with open("%s.csv" % Path(_file).name[: -len(Path(_file).suffix)],
"w+") as _file:
# find orders and DNIs
coords = re.compile(r"\d?\.?\d+\.+\d+\,\d{2}")
results = re.findall(coords, text.decode())
if results:
_file.write("|".join(results))
if __name__ == "__main__":
_file = "/home/cristian33/python_proj/folder1/buscarco.pdf"
main(_file)
when I run it give me the follow error:
The command pdf2txt.py /home/cristian33/python_proj/folder1/buscarco.pdf failed because the executable
pdf2txt.py is not installed on your system. Please make
sure the appropriate dependencies are installed before using
textract:
http://textract.readthedocs.org/en/latest/installation.html
somebody knows why is that error?
thanks
Here is a toy code that I'm playing with:
from __future__ import division
from pyomo.environ import *
from pyomo.opt import SolverStatus, TerminationCondition
import sys
sys.path.append('/Library/gurobi810/mac64/lib/gurobipy')
model = ConcreteModel()
model.x = Var([1,2], domain=NonNegativeReals)
model.obj = Objective(expr = 2*model.x[1] + 3*model.x[2])
model.constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
opt = SolverFactory('gurobi_direct')
#opt = SolverFactory('gurobi')
#opt = SolverFactory('gurobi', solver_io='python')
rr = opt.solve(model)
The above code works fine, with either solver_io='python' or with 'gurobi_direct' only in a Python 2.7 virtual environment. When I'm working in a Python 3.6 virtual environment, I get the following error:
pyutilib.common._exceptions.ApplicationError: No Python bindings available for <class 'pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect'> solver plugin
Does this mean that Pyomo does not support these options for Python 3.6? Any work around?
You need to install the Python bindings for Gurobi with your python 3.6 virtual environment as well (using python setup.py install in the Gurobi bindings)
This might have been answered before, but I could not find anything that addresses my issue.
So, I have 2 files.
|
|-- test.py
|-- test1.py
test1.py is as below
def fnc():
return np.ndarray([1,2,3,4])
I'm trying to call test1 from test and calling the function like
from test1 import *
x = fnc()
Now naturally I'm getting NameError: name 'np' is not defined.
I tried to write the import both in test and test1 as
import numpy as np
But still, I'm getting the error. This might be silly, but what exactly I'm missing?
Any help is appreciated. Thanks in advance.
Each Python module has it's own namespace, so if some functions in test1.py depends on numpy, you have to import numpy in test1.py:
# test1.py
import numpy as np
def fnc():
return np.ndarray([1,2,3,4])
If test.py doesn't directly use numpy, you don't have to import it again, ie:
# test.py
# NB: do NOT use 'from xxx import *' in production code, be explicit
# about what you import
from test1 import fnc
if __name__ == "__main__":
result = fnc()
print(result)
Now if test.py also wants to use numpy, it has to import it too - as I say, each module has it's own namespace:
# test.py
# NB: do NOT use 'from xxx import *' in production code, be explicit
# about what you import
import numpy as np
from test1 import fnc
def other():
return np.ndarray([3, 44, 5])
if __name__ == "__main__":
result1 = fnc()
print(result1)
result2 = other()
print(result2)
Note that if you were testing your code in a python shell, just modifying the source and re-importing it in the python shell will not work (modules are only loaded once per process, subsequent imports fetch the already loaded module from the sys.modules cache), so you have to exit the shell and open a new one.
mostly you need to have __init__.py in the directort where you have these files
just try creating init.py file like below in the directory where you .py files are present and see if it helps.
touch __init__.py
from __future__ import division
import math
from sympy import *
d=symbol('d')
x=solve(d**2 - 224*d + 400)
print(x)
Hi,I'm new to python.I just tried to solve a polynomial expression using symPy,but got the following error.
Traceback (most recent call last):
File "C:/Windows/System32/test.py", line 4, in <module>
d=symbol('d')
TypeError: 'module' object is not callable
Someone pls help me out with the correct function.Thank you
You're sure you are running python3, and your script is not named something that conflicts with any other modules? Do you have a file named sympy.py in your script's directory? (You shouldn't)
I never use import *, you never know what kind of namespace errors you'll run into. This code works 100% for me:
#!/usr/bin/env python3
import math
import sympy
d = sympy.Symbol('d')
x = sympy.solve(d**2 - 224*d + 400)
print(x) # Prints [-4*sqrt(759) + 112, 4*sqrt(759) + 112]
x = sympy.solve(d - 10)
print(x) # Prints 10
capitalize Symbol and try again.
try with d = Symbol('d'). Doing symbol('d') you are trying to use the symbol sub-module as a function which is invalid. Also as you are in python 3 you don't need that future import