scikit-learn optionparser error - python

From the classification example on the website of scikit-learn, I'm getting the following error after executing the part with optionparser:
Usage: __main__.py [options]
__main__.py: error: no such option: -f
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
To exit: use 'exit', 'quit', or Ctrl-D.
a %tb command gives the following output:
---------------------------------------------------------------------------
BadOptionError Traceback (most recent call last)
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in parse_args(self, args, values)
1385 try:
-> 1386 stop = self._process_args(largs, rargs, values)
1387 except (BadOptionError, OptionValueError) as err:
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in _process_args(self, largs, rargs, values)
1429 # value(s) for the last one only)
-> 1430 self._process_short_opts(rargs, values)
1431 elif self.allow_interspersed_args:
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in _process_short_opts(self, rargs, values)
1511 if not option:
-> 1512 raise BadOptionError(opt)
1513 if option.takes_value():
BadOptionError: no such option: -f
During handling of the above exception, another exception occurred:
SystemExit Traceback (most recent call last)
<ipython-input-10-960f3b27132a> in <module>()
66 "headers, signatures, and quoting.")
67
---> 68 (opts, args) = op.parse_args()
69 if len(args) > 0:
70 op.error("this script takes no arguments.")
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in parse_args(self, args, values)
1386 stop = self._process_args(largs, rargs, values)
1387 except (BadOptionError, OptionValueError) as err:
-> 1388 self.error(str(err))
1389
1390 args = largs + rargs
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in error(self, msg)
1566 """
1567 self.print_usage(sys.stderr)
-> 1568 self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
1569
1570 def get_usage(self):
/Users/kevinoost/anaconda/lib/python3.5/optparse.py in exit(self, status, msg)
1556 if msg:
1557 sys.stderr.write(msg)
-> 1558 sys.exit(status)
1559
1560 def error(self, msg):
SystemExit: 2
According to the docs, optparse was deprecated in version 2.7 of Python; and I am using Python 3.
What do I do to fix this?
Thank you,
Regards, Kevin

Related

python pathlib resolve does not support Chinese character on windows

On my windows,
pathlib.Path('R:/人')
has no problem to give
WindowsPath('R:/人')
However,
pathlib.Path('R:/人').resolve()
gives
--------------------------------------------------------------------------- OSError Traceback (most recent call
last) in
----> 1 pathlib.Path('R:/人').resolve()
~\anaconda3\lib\pathlib.py in resolve(self, strict) 1178 if
self._closed: 1179 self._raise_closed()
-> 1180 s = self._flavour.resolve(self, strict=strict) 1181 if s is None: 1182 # No symlink resolution => for
consistency, raise an error if
~\anaconda3\lib\pathlib.py in resolve(self, path, strict)
203 while True:
204 try:
--> 205 s = self._ext_to_normal(_getfinalpathname(s))
206 except FileNotFoundError:
207 previous_s = s
OSError: [WinError 1] 函数不正确。: 'R:\人'
What is the problem with resolve in pathlib?
On the other hand,
pathlib.Path('R:/人').absolute()
correctly gives
WindowsPath('R:/人')

Google AdManager getCurrentNetwork() error

I have set up ad manager credentials. I'm trying to access the Admanager API, im getting the following error.
from googleads import ad_manager
client = ad_manager.AdManagerClient.LoadFromStorage()
network_service = client.GetService('NetworkService', version='v201902')
current_network = network_service.getCurrentNetwork()
the error im facing is:
Fault Traceback (most recent call last)
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1381 return soap_service_method(
-> 1382 *packed_args, _soapheaders=soap_headers)['body']['rval']
1383 except zeep.exceptions.Fault as e:
~\Anaconda3\lib\site-packages\zeep\proxy.py in __call__(self, *args, **kwargs)
41 self._proxy._client, self._proxy._binding_options,
---> 42 self._op_name, args, kwargs)
43
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in send(self, client, options, operation, args, kwargs)
131
--> 132 return self.process_reply(client, operation_obj, response)
133
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_reply(self, client, operation, response)
193 if response.status_code != 200 or fault_node is not None:
--> 194 return self.process_error(doc, operation)
195
~\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py in process_error(self, doc, operation)
287 actor=None,
--> 288 detail=etree_to_string(doc))
289
Fault: Unknown fault occured
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-16-991c0839fc99> in <module>()
----> 1 current_network = network_service.getCurrentNetwork()
~\Anaconda3\lib\site-packages\googleads\common.py in MakeSoapRequest(*args)
1385 if e.detail is not None:
1386 underlying_exception = e.detail.find(
-> 1387 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
1388 fault_type = self.zeep_client.get_element(
1389 '{%s}ApiExceptionFault' % self._GetBindingNamespace())
TypeError: a bytes-like object is required, not 'str'
You are probably missing permissions with your configured service account. Make sure the account has access to ad-manager and scopes are configured properly.
I suggest to do it this way:
class Adx:
def __init__(self):
self.GOOGLEADS_YAML = 'googleads.yaml'
self.GOOGLEADS_VERSION = 'v202111'
self.google_keys = self.GOOGLEADS_YAML
def activate(self):
ad_manager_client = ad_manager.AdManagerClient.LoadFromStorage(self.google_keys)

Runtime error in apply() function of python

I am doing a ML course on Coursera
When I run the following command
sf['Country'] = sf['Country'].apply(transform_country)
Following is the error i get
RuntimeError Traceback (most recent call last)
<ipython-input-10-e97a176c3eea> in <module>()
----> 1 sf['Country'] = sf['Country'].apply(transform_country)
F:\Anaconda2\envs\gl-env\lib\site-packages\graphlab\data_structures\sarray.pyc in apply(self, fn, dtype, skip_undefined, seed)
1892
1893 with cython_context():
-> 1894 return SArray(_proxy=self.__proxy__.transform(fn, dtype, skip_undefined, seed))
1895
1896
F:\Anaconda2\envs\gl-env\lib\site-packages\graphlab\cython\context.pyc in __exit__(self, exc_type, exc_value, traceback)
47 if not self.show_cython_trace:
48 # To hide cython trace, we re-raise from here
---> 49 raise exc_type(exc_value)
50 else:
51 # To show the full trace, we do nothing and let exception propagate
RuntimeError: Runtime Exception. Cannot evaluate lambda. Lambda workers cannot not start.
What do I do now ?

Unable to understand sys.argv while solving the systemExit error

I am trying to run a code,
if __name__ == "__main__":
print ("hello")
manager()
I am getting the following error:
Error: no such option: -f
An exception has occurred, use %tb to see the full traceback.
SystemExit: 2
On running
%tb
I am getting the following:
---------------------------------------------------------------------------
SystemExit Traceback (most recent call last)
<ipython-input-16-7c8a2c69be4e> in <module>()
165
166 if __name__ == "__main__":
--> 167 manager()
C:\Users\Anaconda2\lib\site-packages\click\core.pyc in __call__(self, *args, **kwargs)
720 def __call__(self, *args, **kwargs):
721 """Alias for :meth:`main`."""
--> 722 return self.main(*args, **kwargs)
723
724
C:\Users\Anaconda2\lib\site-packages\click\core.pyc in main(self, args, prog_name, complete_var, standalone_mode, **extra)
706 raise
707 e.show()
--> 708 sys.exit(e.exit_code)
709 except IOError as e:
710 if e.errno == errno.EPIPE:
SystemExit: 2
I followed the instruction and ran:
sys.argv
I got the following:
['C:\\Users\\Anaconda2\\lib\\site-packages\\ipykernel\\__main__.py',
'-f',
'C:\\Users\\AppData\\Roaming\\jupyter\\runtime\\kernel-85f59a10-ccfe-4f4e-8ba7-72b1d24e60ef.json']
I really don't understand what parameters I need to pass and why?
def manager():
pass

Catching HTTPerror in python3 from stravalib function

My code (for the relevant part) is as follows
myactivities = []
from urllib.error import HTTPError
for activity in client.get_activities(after = activities_from, before=activities_to):
print(activity)
print(activity.id, activity.start_date)
try:
temp = client.get_activity_streams(activity.id, types=types)
except urllib.error.HTTPError:
print("HTTPError")
myactivities.append(temp)
The error print I get is this:
HTTPError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
----> 9 temp = client.get_activity_streams(activity.id, types=types)
10 except urllib.error.HTTPError:
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in get_activity_streams(self, activity_id, types, resolution, series_type)
1174 # Pack streams into dictionary
-> 1175 return {i.type: i for i in streams}
1176
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in <dictcomp>(.0)
1174 # Pack streams into dictionary
-> 1175 return {i.type: i for i in streams}
1176
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in __next__(self)
1529 def __next__(self):
-> 1530 return self.next()
1531
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in next(self)
1535 if not self._buffer:
-> 1536 self._fill_buffer()
1537 try:
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\client.py in _fill_buffer(self)
1506
-> 1507 raw_results = self.result_fetcher(page=self._page, per_page=self.per_page)
1508
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in get(self, url, check_for_errors, use_webhook_server, **kwargs)
245 params = dict([(k, v) for k, v in kwargs.items() if not k in referenced])
--> 246 return self._request(url, params=params, check_for_errors=check_for_errors, use_webhook_server=use_webhook_server)
247
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in _request(self, url, params, files, method, check_for_errors, use_webhook_server)
169 if check_for_errors:
--> 170 self._handle_protocol_error(raw)
171
C:\Users\Koti\Anaconda3\lib\site-packages\stravalib\protocol.py in _handle_protocol_error(self, response)
214 if x is not None:
--> 215 raise x
216
HTTPError: 404 Client Error: Not Found [Record Not Found: []]
During handling of the above exception, another exception occurred:
NameError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
9 temp = client.get_activity_streams(activity.id, types=types)
---> 10 except urllib.error.HTTPError:
11 print("HTTPError")
12 myactivities.append(temp)
NameError: name 'urllib' is not defined
How can I catch that HTTPError succesfully? I tried all the suggestions in catch specific HTTP error in python but none helped.
Try
myactivities = []
from urllib.error import HTTPError
for activity in client.get_activities(after = activities_from, before=activities_to):
print(activity)
print(activity.id, activity.start_date)
try:
temp = client.get_activity_streams(activity.id, types=types)
except HTTPError:
print("HTTPError")
myactivities.append(temp)
You already imported HTTPError, you have to use directly.
Your code shows error.
NameError Traceback (most recent call last)
<ipython-input-29-fc30cef1e4f3> in <module>()
8 try:
9 temp = client.get_activity_streams(activity.id, types=types)
---> 10 except urllib.error.HTTPError:
11 print("HTTPError")
12 myactivities.append(temp)
NameError: name 'urllib' is not defined
Which gives error because urllib is not accessible. You imported HTTPError from that.

Categories

Resources