Read GCS file into dask dataframe - google-cloud-storage

I want to read a csv file stored in Google Cloud Storage using dask dataframe.
I have insalled gcsfs & dask in the conda env. on Windows
import dask.dataframe as dd
import gcsfs
project_id = 'my-project'
token_file = 'C:\\path\to\credentials.json'
fs = gcsfs.GCSFileSystem(project=project_id)
gcs_bucket_name = 'my_bucket'
df = dd.read_csv('gs://'+gcs_bucket_name+'/my_file.csv',storage_options={'token': token_file, 'project': project_id})
I know I'm not providing the key file correctly as per
https://gcsfs.readthedocs.io/en/latest/ but not sure how to do it. Can anyone please help?
Error I'm getting -
File "<ipython-input-XXXXXXXX>", line 1, in <module>
runfile('C:/path/to/scripts/my_python_script.py', wdir='C:/path/to/scripts')
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/path/to/scripts/my_python_script.py", line 28, in <module>
df = dd.read_csv('gcs://'+gcs_bucket_name+'/my_file.csv',storage_options={'token': token_file, 'project': project_id})
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\dask\dataframe\io\csv.py", line 578, in read
**kwargs
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\dask\dataframe\io\csv.py", line 444, in read_pandas
head = reader(BytesIO(b_sample), **kwargs)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\pandas\io\parsers.py", line 685, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\pandas\io\parsers.py", line 463, in _read
data = parser.read(nrows)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\pandas\io\parsers.py", line 1154, in read
ret = self._engine.read(nrows)
File "C:\Users\AppData\Local\Continuum\anaconda3\envs\my-rdkit-env\lib\site-packages\pandas\io\parsers.py", line 2059, in read
data = self._reader.read(nrows)
File "pandas/_libs/parsers.pyx", line 881, in pandas._libs.parsers.TextReader.read
File "pandas/_libs/parsers.pyx", line 896, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas/_libs/parsers.pyx", line 950, in pandas._libs.parsers.TextReader._read_rows
File "pandas/_libs/parsers.pyx", line 937, in pandas._libs.parsers.TextReader._tokenize_rows
File "pandas/_libs/parsers.pyx", line 2132, in pandas._libs.parsers.raise_parser_error
ParserError: Error tokenizing data. C error: Expected 4 fields in line 3, saw 134

Related

SQLFluff Lint not working for multilevel subdirectory sql file

we are trying to use SQLFluff in our project to avoid sql parser errors before deployment.
in our case we have subdirectories which contains sql files.
During Development we are running command sqlfluff lint command in root directory, we found that lint command is working for one level subdirectory sql path like below,
sqlfluff lint demo/complexquery.sql --dialect snowflake
But when we try for 2 level subdirectory sql file path, lint command is not working and giving error as below. could you please let me know whether iam missing syntax.
sqlfluff lint SQLScript/demo/complexquery.sql --dialect snowflake
Traceback (most recent call last):
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\toml\decoder.py", line 395, in loads
value, vtype = decoder.load_value(multilinestr)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\toml\decoder.py", line 849, in load_value
raise ValueError("Found tokens after a closed " +
ValueError: Found tokens after a closed string. Invalid TOML.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\ar\AppData\Roaming\Python\Python310\Scripts\sqlfluff.exe_main.py", line 7, in
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1130, in call
return self.main(*args, **kwargs)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1055, in main
rv = self.invoke(ctx)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\click\core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\cli\commands.py", line 549, in lint
config = get_config(
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\cli\commands.py", line 361, in get_config
return FluffConfig.from_root(
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 613, in from_root
c = loader.load_config_up_to_path(
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 414, in load_config_up_to_path
[self.load_config_at_path(p) for p in config_paths]
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 414, in
[self.load_config_at_path(p) for p in config_paths]
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 338, in load_config_at_path
configs = self.load_config_file(p, fname, configs=configs)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 305, in load_config_file
elems = self._get_config_elems_from_toml(file_path)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\sqlfluff\core\config.py", line 191, in _get_config_elems_from_toml
config = toml.load(fpath)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\toml\decoder.py", line 134, in load
return loads(ffile.read(), _dict, decoder)
File "C:\Users\ar\AppData\Roaming\Python\Python310\site-packages\toml\decoder.py", line 397, in loads
raise TomlDecodeError(str(err), original, pos)
toml.decoder.TomlDecodeError: Found tokens after a closed string. Invalid TOML. (line 54 column 1 char 4192)

Unable to initialise Spark

I'm trying to initialise spark using pyspark in Spyder (IDE) but always get error. (OS - Ubuntu 16.04 LTS)
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
File "<ipython-input-7-86b3963ebca1>", line 3, in <module>
.appName("test_import")\
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/sql/session.py", line 173, in getOrCreate
sc = SparkContext.getOrCreate(sparkConf)
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/context.py", line 349, in getOrCreate
SparkContext(conf=conf or SparkConf())
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/context.py", line 118, in __init__
conf, jsc, profiler_cls)
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/context.py", line 187, in _do_init
self._accumulatorServer = accumulators._start_update_server(auth_token)
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/accumulators.py", line 291, in _start_update_server
server = AccumulatorServer(("localhost", 0), _UpdateRequestHandler, auth_token)
File "/home/fly/anaconda3/lib/python3.7/site-packages/pyspark/accumulators.py", line 274, in __init__
SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass)
File "/home/fly/anaconda3/lib/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/home/fly/anaconda3/lib/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
gaierror: [Errno -2] Name or service not known
This is most likely because you aren't able to connect with the spark-master. Go to your /etc/hosts file and add this line to it.
127.0.0.1 localhost

Failing to install pandas due to an error

I am Failing to install pandas in cmd using pip-install pandas due to the error below that pops up when installing. I am using python version 3.7
Traceback (most recent call last):
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 360, in _error_catcher
yield
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 442, in read
data = self._fp.read(amt)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\http\client.py", line 447, in read
n = self.readinto(b)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\http\client.py", line 491, in readinto
n = self.fp.readinto(b)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\base_command.py", line 179, in main
status = self.run(options, args)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\install.py", line 315, in run
resolver.resolve(requirement_set)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\resolve.py", line 131, in resolve
self._resolve_one(requirement_set, req)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\resolve.py", line 294, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\resolve.py", line 242, in _get_abstract_dist_for
self.require_hashes
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\operations\prepare.py", line 334, in prepare_linked_requirement
progress_bar=self.progress_bar
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 878, in unpack_url
progress_bar=progress_bar
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 702, in unpack_http_url
progress_bar)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 946, in _download_http_url
_download_url(resp, link, content_file, hashes, progress_bar)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 639, in _download_url
hashes.check_against_chunks(downloaded_chunks)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\utils\hashes.py", line 62, in check_against_chunks
for chunk in chunks:
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 607, in written_chunks
for chunk in chunks:
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\utils\ui.py", line 159, in iter
for x in it:
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 596, in resp_read
decode_content=False):
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 494, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 459, in read
raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "c:\users\chiya\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\urllib3\response.py", line 365, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
I tried updating pip with the command pip install -U pip setuptools
but it showed that pip is up to date.
I tried again pip install fbchat which downloaded successfully but after trying to install pandas with the same "pip install pandas" the error popped up again.**

Enthought Canopy GUI won't open

I've downloaded Enthought Canopy Express onto my 64-bit Windows 10 laptop, but when I try to open the Canopy program it won't open.
If I try to open it from the desktop shortcut or go into the program files and try to open it directly from the .exe file, all it will do is show the splash page, which then disappears after showing for a few seconds, and then nothing happens. Also after the splash page is gone, task manager shows that Canopy isn't running.
The PyLab application will open and works fine, but I need the actual Enthought Canopy application to work for a class I'm taking.
When I installed it for the very first time, it did open and I was able to use the Enthought Canopy application, but ever since I closed out of it since then it hasn't worked.
When I go into the program files to try and open it from the .exe file, for the file Canopy.exe it will open the splash page and then close, and for Canopy_cli.exe it will open a command prompt looking window, then the splash page, and then both close. The file _python.exe will open and work, and the file _pythonw.exe does nothing.
(These files are at C:\Users\charizard\AppData\Local\Enthought\Canopy\App if that makes any difference.)
I've uninstalled and restarted and reinstalled several times, and I've tried the "Full Reset" suggested in this article. My user name is just "charizard" and my computer name is "messier42", so the problem isn't that it's a non-ASCII user name.
I have also tried the test to see if it's a problem with the PYTHONPATH or PYTHONHOME environment variables like it suggests in this article, but it didn't start Canopy.
This is what I got from the command prompt when I tested that:
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\charizard>
C:\Users\charizard>set pythonpath=
C:\Users\charizard>set pythonhome=
C:\Users\charizard>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\charizard\AppData\Roaming
asl.log=Destination=file
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=MESSIER42
ComSpec=C:\WINDOWS\system32\cmd.exe
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\charizard
LOCALAPPDATA=C:\Users\charizard\AppData\Local
LOGONSERVER=\\MicrosoftAccount
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Broadcom\Broadcom 802.11 Network Adapter;;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Acer\Remote Files\;C:\Program Files (x86)\Calibre2\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;c:\users\charizard\appdata\local\enthought\canopy\user\scripts;C:\Users\charizard\AppData\Roaming\Dashlane\3.5.2.91395\bin\Firefox_Extension\{442718d9-475e-452a-b3e1-fb1ee16b8e9f}\components;C:\Users\charizard\AppData\Local\Enthought\Canopy\User;C:\Users\charizard\AppData\Local\Enthought\Canopy\User\Scripts
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=4501
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\Users\CHARIZ~1\AppData\Local\Temp
TMP=C:\Users\CHARIZ~1\AppData\Local\Temp
USERDOMAIN=MESSIER42
USERDOMAIN_ROAMINGPROFILE=MESSIER42
USERNAME=charizard
USERPROFILE=C:\Users\charizard
windir=C:\WINDOWS
[.... later after correcting typo...]
C:\Users\charizard>cd "%localappdata%\enthought\canopy\app"
C:\Users\charizard\AppData\Local\Enthought\Canopy\App>_python.exe canopy-script.pyw
Traceback (most recent call last):
File "canopy-script.pyw", line 776, in <module>
File "canopy-script.pyw", line 336, in bootstrap
File "canopy-script.pyw", line 363, in chainload
File "canopy-script.pyw", line 762, in _chainload
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Canopy-script.pyw", line 8, in <module>
sys.exit(main())
File "build\bdist.win-amd64\egg\canopy\app\bootstrap.py", line 2421, in main
File "build\bdist.win-amd64\egg\canopy\app\bootstrap.py", line 2357, in send_bug_report
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 25, in <module>
File "build\bdist.win-amd64\egg\canopy\app\application.py", line 22, in <module>
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\envisage\ui\tasks\api.py", line 2, in <module>
from preferences_pane import PreferencesPane
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\envisage\ui\tasks\preferences_pane.py", line 4, in <module>
from traitsui.api import Controller
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\traitsui\api.py", line 41, in <module>
from .editors.api import (BooleanEditor, ButtonEditor,
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\traitsui\editors\__init__.py", line 27, in <module>
from .api import (toolkit, BooleanEditor, ButtonEditor,
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\traitsui\editors\api.py", line 8, in <module>
from .array_editor import ArrayEditor
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\traitsui\editors\array_editor.py", line 27, in <module>
import numpy
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\numpy\__init__.py", line 185, in <module>
from . import add_newdocs
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\Lib\site-packages\numpy\lib\__init__.py", line 17, in <module>
from . import scimath as emath
ImportError: cannot import name scimath
C:\Users\charizard\AppData\Local\Enthought\Canopy\App>
C:\Users\charizard\AppData\Local\Enthought\Canopy\App>Uncaught exception captured
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "build\bdist.win-amd64\egg\canopy\app\main.py", line 53, in main
File "build\bdist.win-amd64\egg\canopy\app\application_launcher.py", line 350, in launch
File "build\bdist.win-amd64\egg\canopy\app\application.py", line 361, in run
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\ui\tasks\tasks_application.py", line 131, in run
started = self.start()
File "build\bdist.win-amd64\egg\canopy\app\application.py", line 295, in start
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\application.py", line 295, in start
self.plugin_manager.start()
File "build\bdist.win-amd64\egg\canopy\app\canopy_plugin_manager.py", line 140, in start
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\composite_plugin_manager.py", line 133, in start
self.start_plugin(plugin)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\composite_plugin_manager.py", line 143, in start_plugin
plugin.activator.start_plugin(plugin)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\plugin_activator.py", line 30, in start_plugin
plugin.start()
File "build/bdist.macosx-10.6-x86_64/egg/canopy_data_import_addon/plugin.py", line 79, in start
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\application.py", line 370, in get_service
protocol, query, minimize, maximize
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 77, in get_service
services = self.get_services(protocol, query, minimize, maximize)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 114, in get_services
actual_protocol, name, obj, properties, service_id
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 258, in _resolve_factory
obj = obj(**properties)
File "build\bdist.win-amd64\egg\canopy\plugin\plugin.py", line 183, in _create_package_manager_service
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\application.py", line 370, in get_service
protocol, query, minimize, maximize
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 77, in get_service
services = self.get_services(protocol, query, minimize, maximize)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 114, in get_services
actual_protocol, name, obj, properties, service_id
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\envisage\service_registry.py", line 258, in _resolve_factory
obj = obj(**properties)
File "build\bdist.win-amd64\egg\canopy\accounts\plugin.py", line 69, in _create_account_service
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 359, in __init__
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3285, in _init_trait_listeners
getattr( self, '_init_trait_%s_listener' % data[0] )( name, *data )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3340, in _init_trait_delegate_listener
self.on_trait_change( notify, name_pattern, target=self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 2584, in on_trait_change
listener.register( self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 433, in register
value = getattr( self, type )( new, name, False )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 701, in _register_simple
return next.register( getattr( object, name ) )
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 308, in _preferences_default
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 314, in _enstaller_config_default
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 299, in from_file
ret = _create(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 268, in _create
parsed = parse_assignments(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 207, in parse_assignments
return _AssignmentParser().parse(file_or_filename.read())
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 172, in parse
root = ast.parse(s)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <canopy.logging.logging_service.LoggingService object at 0x00000000054EAA98>, trait: exception_added, old value: <undefined>, new value: <LogRecord: root, 40, build\bdist.win-amd64\egg\canopy\logging\logging_service.py, 154, "Uncaught exception captured">
Traceback (most recent call last):
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\trait_notifiers.py", line 340, in __call__
self.handler( *args )
File "build\bdist.win-amd64\egg\canopy\logging\logging_service.py", line 203, in _exception_added_fired
File "build\bdist.win-amd64\egg\canopy\logging\logging_service.py", line 187, in _report_exception
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 505, in start
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 192, in __init__
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 221, in setup_ui
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 304, in __init__
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 269, in _requester_email_default
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 261, in _account_service_default
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 359, in __init__
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3285, in _init_trait_listeners
getattr( self, '_init_trait_%s_listener' % data[0] )( name, *data )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3340, in _init_trait_delegate_listener
self.on_trait_change( notify, name_pattern, target=self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 2584, in on_trait_change
listener.register( self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 433, in register
value = getattr( self, type )( new, name, False )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 701, in _register_simple
return next.register( getattr( object, name ) )
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 308, in _preferences_default
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 314, in _enstaller_config_default
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 299, in from_file
ret = _create(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 268, in _create
parsed = parse_assignments(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 207, in parse_assignments
return _AssignmentParser().parse(file_or_filename.read())
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 172, in parse
root = ast.parse(s)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
Exception occurred in traits notification handler for object: <canopy.logging.logging_service.LoggingService object at 0x00000000054EAA98>, trait: exception_added, old value: <undefined>, new value: <LogRecord: root, 40, build\bdist.win-amd64\egg\canopy\logging\logging_service.py, 154, "Uncaught exception captured">
Traceback (most recent call last):
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\trait_notifiers.py", line 340, in __call__
self.handler( *args )
File "build\bdist.win-amd64\egg\canopy\logging\logging_service.py", line 203, in _exception_added_fired
File "build\bdist.win-amd64\egg\canopy\logging\logging_service.py", line 187, in _report_exception
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 505, in start
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 192, in __init__
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 221, in setup_ui
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter_view.py", line 304, in __init__
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 269, in _requester_email_default
File "build\bdist.win-amd64\egg\canopy\feedback\data_reporter.py", line 261, in _account_service_default
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 359, in __init__
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3285, in _init_trait_listeners
getattr( self, '_init_trait_%s_listener' % data[0] )( name, *data )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 3340, in _init_trait_delegate_listener
self.on_trait_change( notify, name_pattern, target=self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\has_traits.py", line 2584, in on_trait_change
listener.register( self )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 433, in register
value = getattr( self, type )( new, name, False )
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\traits\traits_listener.py", line 701, in _register_simple
return next.register( getattr( object, name ) )
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 308, in _preferences_default
File "build\bdist.win-amd64\egg\canopy\accounts\account_service.py", line 314, in _enstaller_config_default
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 299, in from_file
ret = _create(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\enstaller\config.py", line 268, in _create
parsed = parse_assignments(fp)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 207, in parse_assignments
return _AssignmentParser().parse(file_or_filename.read())
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\site-packages\egginst\utils.py", line 172, in parse
root = ast.parse(s)
File "C:\Users\charizard\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.5.3123.win-x86_64\lib\ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
TypeError: compile() expected string without null bytes
Please zip and email your file C:\Users\charizard\.enstaller4rc to support#enthought.com for forensics, and refer to this SO article. Then just delete that file, and I expect that you'll be able to start Canopy ok.

can not rename column using alter_column

I have an existing project that is based on pylons and sqlalchemy. I did not use alembic or any wrapper in this project, yet.
I migrated the project to flask and sqlalchemy.
I took the old database of the old version 1.5 and generated the first migration script with Flast-Migrate. Hm, I realized I will have to do many things manually.
I am already stuck, when renaming columns. I am doing this with an SQLite database.
The old project had a table "Token", which was renamed to "token". Obviously there are some database that do not care about upper or lower case.
When I try to rename the first column like this:
op.alter_column('token', 'privacyIDEATokenId', new_column_name='id')
I get this error:
sqlalchemy.exc.OperationalError: (OperationalError) near \
""privacyIDEATokenId"": syntax error u'ALTER TABLE token RENAME \
"privacyIDEATokenId" TO id' ()
The column Token.privacyIDEATokenId is the primary key that should be token.id in the new version.
The same happens to columns that are not the primary key.
Full trace:
Traceback (most recent call last):
File "./manage.py", line 107, in <module>
manager.run()
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
res = handle(*args, **config)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/flask_script/commands.py", line 216, in __call__
return self.run(*args, **kwargs)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/flask_migrate/__init__.py", line 98, in upgrade
command.upgrade(config, revision, sql = sql, tag = tag)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/command.py", line 129, in upgrade
script.run_env()
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/script.py", line 208, in run_env
util.load_python_file(self.dir, 'env.py')
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/util.py", line 230, in load_python_file
module = load_module_py(module_id, path)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/compat.py", line 63, in load_module_py
mod = imp.load_source(module_id, path, fp)
File "migrations/env.py", line 72, in <module>
run_migrations_online()
File "migrations/env.py", line 65, in run_migrations_online
context.run_migrations()
File "<string>", line 7, in run_migrations
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/environment.py", line 696, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/migration.py", line 266, in run_migrations
change(**kw)
File "migrations/versions/112475c7f45_.py", line 103, in upgrade
_upgrade_token_table()
File "migrations/versions/112475c7f45_.py", line 49, in _upgrade_token_table
op.alter_column('token', 'privacyIDEATokenId', new_column_name='id')
File "<string>", line 7, in alter_column
File "<string>", line 1, in <lambda>
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/util.py", line 353, in go
return fn(*arg, **kw)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/operations.py", line 329, in alter_column
existing_autoincrement=existing_autoincrement
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 131, in alter_column
existing_nullable=existing_nullable,
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 81, in _exec
conn.execute(construct, *multiparams, **params)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 729, in execute
return meth(self, multiparams, params)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 69, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 783, in _execute_ddl
compiled
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 958, in _execute_context
context)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1159, in _handle_dbapi_exception
exc_info
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 951, in _execute_context
context)
File "/home/cornelius/src/privacyidea/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 436, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (OperationalError) near ""privacyIDEATokenId"": syntax error u'ALTER TABLE token RENAME "privacyIDEATokenId" TO id' ()
Nowadays you can use "batch migration" to enable ALTER-ing columns under SQLite:
with op.batch_alter_table('table_name') as bop:
bop.alter_column('old_column_name', new_column_name='new_name')
Obivously sqlite can not rename a column. So finally I ended up with creating new tables with new columns and shoving data from one to the other.
This is ok, since I realized, I also have to mangle the data, adapt and modify it before writing to the new table again.
The script I ended up with, is here:
https://github.com/privacyidea/privacyidea/blob/version2/migrations/versions/4f32a4e1bf33_.py#L241