I installed JPype in a correct way and anything is fine and my instalation was succeed but when i run my refactor.py from command prompt i have error that i pointed in title.
i hope you can help me for solving this problem.
also i have to point that i am beginner in python3.
here is my code:
import urllib.request
import os
import tempfile
import sys
import fileinput
import logging
import jpype
logging.basicConfig(filename="ERROR.txt", level= logging.ERROR)
try:
logging.debug('we are in the main try loop')
jpype.startJVM("C:/Users/user/AppData/Local/Programs/Python/Python36/ClassWithTest.java", "-ea")
test_class = jpype.JClass("ClassWithTest")
a = testAll()
file_java_class = open("OUTPUT.txt", "w")
file_java_class.write(a)
except Exception as e1:
logging.error(str(e1))
jpype.shutdownJVM()
startJVM() function takes the path to the JVM which is like this - C:\\Program Files\\Java\\jdk-10.0.2\\bin\\server\\jvm.dll. You could use the getDefaultJVMPath() function to get the JVM path on your PC. So you can just start the JVM this way:
startJVM(getDefaultJVMPath(), "-ea")
Hope that helps!
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 keep getting an error trying to connect Cloud Run and I keep getting the following error. Any idea?
__import__("pg8000") ModuleNotFoundError: No module named 'pg8000'
import pandas as pd
import sqlalchemy
import datetime
import requests
from urllib.parse import urlencode
import warnings
from flask import Flask
import os
import google
db_user = os.environ.get("DB_USER")
db_pass = os.environ.get("DB_PASS")
db_name = os.environ.get("DB_NAME")
cloud_sql_connection_name = os.environ.get("CLOUD_SQL_CONNECTION_NAME")
db = sqlalchemy.create_engine(
# Equivalent URL:
# postgres+pg8000://<db_user>:<db_pass>#/<db_name>?unix_sock=/cloudsql/<cloud_sql_instance_name>/.s.PGSQL.5432
sqlalchemy.engine.url.URL(
drivername='postgres+psycopg2',
username=db_user,
password=db_pass,
database=db_name,
query={
'unix_sock': '/cloudsql/{}/.s.PGSQL.5432'.format(
cloud_sql_connection_name)
}
),
# ... Specify additional properties here.
# ...
)
You need to install one of the supported database drivers.
If you want to use postgres+pg8000, you need to install the pg8000 package, otherwise based on your example, you actually need to install psycopg2.
I used python3.7 in windows7.
When I tried to run this line: suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
error occurs: module 'subprocess' has no attribute '_subprocess'
import os
import sqlite3
import subprocess
import time
import re
from django.core.mail import send_mail
from django.http import HttpResponse
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
How to deal with that?
There is no such thing as subprocess._subprocess, the constant is straight under subprocess:
suinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
See the docs: https://docs.python.org/3/library/subprocess.html#subprocess.STARTF_USESHOWWINDOW
In my image comparision code following: https://www.pyimagesearch.com/2014/09/15/python-compare-two-images/
While using
from skimage.measure import structural_similarity as ssim
and then
s = ssim(imageA, imageB)
I am getting error:
from skimage.measure import structural_similarity as ssim
ImportError: cannot import name 'structural_similarity'
I found the solution. As this question is unique and not covered anywhere. So, posting the answer.
#from skimage.measure import structural_similarity as ssim
from skimage import measure
.
.
.
#s = ssim(imageA, imageB)
s = measure.compare_ssim(imageA, imageB)
Change commented line to uncommented line.
Please check your skimage version.
https://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.compare_ssim
Changed in version 0.16: This function was renamed from skimage.measure.compare_ssim to skimage.metrics.structural_similarity.
Hope it helps.
change import line to
from skimage.metrics import structural_similarity as ssim
This may work better than using compare_ssim since that is going to be deprecated
I use next solution:
from skimage import metrics
metrics.structural_similarity(grayA, grayB, full=True)
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