I created a python notebook in Azure Data Studio and it is working as intended. I saw an article about being able to run notebooks as jobs with an extension. These notebook jobs create a PowerShell script that is executed as a sql agent job. It seems as though this only works with SQL notebooks and not python notebooks based on the error I am getting. For example, I get an error message about the from clause with "from sqlalchemy import create_engine"
However, the PowerShell script that was created contains the kernel and the language meta data, so it almost seems like it should work. But then again, I also don't know much at all about PowerShell.
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3 (ipykernel)",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.8.10",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
}
},
Does anyone know if this is possible? Seems like there could be a work around. It would be a game changer to be able to run python notebooks from SQL Server.
Here is a simple test I did.
I created a python notebook with
x = 5
y = "John"
print(x)
print(y)
The error I get, is exactly the same error as if you try to run that in SSMS
"Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '='.
The name "x" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
The name "y" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted"
Thanks for your time
Related
IN VS CODE i get the error "include file not found in browse. path."
with an error squiggle under my header file #include <stdio.h>
how can i make this library accessible to my code.
all i have is a folder and a main.c file
Very new to all this, the other answers seem to be out of my depth as im not sure what files they're accessing.
Thank you in advance.
Very similar problem to the one posed here, and thankfully a very similar solution.
Ctrl-Shift-P will open the "command bar", start trying C/Cpp: Edit Configurations until it's the top result then hit enter, this will create a c_cpp_properties.json file in the .vscode folder of your current project directory (making this configuration unique to this project, so you'll need to repeat this for other projects). This json file has sections for Mac, Linux and Win32, edit the section relevant to you or all if you know the paths for the other platforms. Each block has a name, includePath, defines, intelliSenseMode and browse property. The browse property has a child array called path (which is what we're looking for, include file not found in *browse.path*), add the paths to your include directories here, one string each, and remember to use forward slashes even if Windows gives you them as backward slashes.
While the offending error disappeared when adding the correct path to browse.path, I also added it to the includePath section because according to the hover tooltip includePath is used by the intellisense engine whereas browse.path is used by the tag parser. Can't hurt to have both set up correctly.
Attaching example of .vscode\c_cpp_properties.json file with browse.path which solved my issues with Arduino dependencies
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTProtocol_MQTT\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTUtility\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTHub\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\WiFiManager\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\ArduinoJson\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.2\\**",""
],
"forcedInclude": [],
"browse": {
"path":[
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTProtocol_MQTT\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTUtility\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\AzureIoTHub\\src\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\WiFiManager\\**",
"C:\\Users\\localuser\\Documents\\Arduino\\libraries\\ArduinoJson\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\localuser\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.4.2\\**"]
},
"intelliSenseMode": "msvc-x64",
"compilerPath": "C:\\WinAVR-20100110\\bin\\avr-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
All you need to have is, to check if browse.path exists in the c_cpp_properties.json file. If not include this part. It should fix the issue.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4 }
I created yesterday a Jupyter notebook file in Python 3 and saved it. I do not know what bad manipulation I did but today, when I want to reopen this file, I realize that it is in plain text format! Is there a way to revert to a python encoded format?
The file doesn't have extension ipynb (It has no extension) ; it looks like this (few first lines):
"cells": [
{
"cell_type": "code",
"execution_count": 377,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\thaly\\anaconda3\\lib\\site-packages\\pandas\\core\\indexing.py:965: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" self.obj[item] = s\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",````
The file you have saved is a Jupyter notebook (internally it is a JSON file).
To convert this notebook, you can:
Just add an extension .ipynb to it,
run Jupyter and open the notebook with it.
Then you will be able to export the content of the notebook in several format such as Python file.
simple open you txt or any file on jupyter notebook
go to the rename option and edit the the name of file with .ipynb (Example file.txt to file.ipynb)
save it and open again.
Maybe you're trying to open the html file without actually starting the notebook and using a text editor instead? You need to start the notebook, for instance, from IPython.
What do I need to put in this file in order to run my program. From the command line normally I navigate to the folder (as my test file is there too) and type:
python main.py test_file.xlsx
So my python script is called main.py and I am sending an excel file as an argument. I can't work out what you are supposed to put in the launch.json file to get it to work I found the args bit from another post, but I have no idea if I have done it correctly as vscode is objecting to its own default launch file comment?:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"args"
"console": "integratedTerminal"
}
]
}
Completely lost with this, why is there not some documentation around this?
Let's start from the top:
The JSON you have pasted above is not valid - objects must be key-value pairs. Your args key does not have a value.
args is an array of strings that are passed in to the command in your configuration. In your case this would be ["${workspaceFolder}/main.py"] if your main is in the root directory of the workspace.
To have a nice dynamic list of secondary arguments (in your case files) you can use the runtimeArgs key. It is also a list of strings, in your case it would be ["test_file.xlsx"]
Documentation about the VSCode debugger can be found here: https://code.visualstudio.com/docs/editor/debugging
Hope this helps :)
I believe other people might have asked similar questions, I don't know if I'm cross posting this, if so, I apologize and will be very appreciated for some hints or links that can guide me through this.
I'm new to sublime text2 but have being using IDLE for python scripting for a while.
The question here is quite simple. so here is the thing.
In IDLE, after I wrote a script and run it with F5, the script will run in a python shell like this:
and I was able to retrieve some of the avriables I defined in my script that was running after the shell finish running the script like this: adm_pop is a dict type I defined in my script.
this is very handy since every time I ran the script I was able to check whether one or two variables were declared correct and value assigned to it is correct. But in sublime text I wasn't able to do this since after the script finished running it just finished. like this:
I wasn't able to do any other input with the console like I can do with IDLE. It's just bugging me a lot so hopely you guys can give me some hints. Thanks in advance!!!!
Go to your Packages folder by selecting Preferences -> Browse Packages.... Go to the User folder and create a SublimeREPL folder containing a config folder containing a Python folder. Then, within that final folder save the following as Main.sublime-menu:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Python",
"id": "Python",
"children":[
{"command": "repl_open",
"caption": "Python",
"id": "repl_python3",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["c:/pythonXX/python.exe", "-i", "-u"],
"cwd": "c:/whichever/path/you/want",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]
}
]
}]
}
]
Change the path in "cmd" to the correct one for your Python installation, and feel free to customize the "cwd" (Current Working Directory) path to whatever you want. This will create a new menu option under Tools -> SublimeREPL -> Python that will be protected from any package upgrades.
I am trying to return JSON from the API service from musicbrainz, the returned data for some songs have unicode characters which I am having trouble converting them to regular symbols etc. Kindly let me know what I should be doing here.
JSON:
{
"status": "ok",
"results": [{
"recordings": [{
"duration": 402,
"tracks": [{
"duration": 402,
"position": 6,
"medium": {
"release": {
"id": "dde6ecee-8e9b-4b46-8c28-0f8d659f83ac",
"title": "Tecno Fes, Volume 2"
},
"position": 1,
"track_count": 11
},
"artists": [{
"id": "57c1e5ea-e08f-413a-bcb1-f4e4b675bead",
"name": "Gigi D\u2019Agostino"
}],
"title": "You Spin Me Round"
}],
"id": "2e0a7bce-9e44-4a63-a789-e8c4d2a12af9"
}, ....
Failed Code (example):
string = '\u0420\u043e\u0441\u0441\u0438\u044f'
print string.encode('utf-8')
I am using this on a windows 7 machine and have python 2.7 and running this code on a command line terminal.. I have the output I get below:
C:\Python27>python junk.py Gigi DGÇÖAgostino Gigi D?Agostino Gigi D\u2019Agostino
I am expecting the output to be Gigi D' Agostino
Unicode escape only works with unicode strings, to convert your regular string to unicode use str.decode('unicode-escape'):
In [1]: s='\u0420\u043e\u0441\u0441\u0438\u044f'
In [2]: s
Out[2]: '\\u0420\\u043e\\u0441\\u0441\\u0438\\u044f'
In [3]: s.decode('unicode-escape')
Out[3]: u'\u0420\u043e\u0441\u0441\u0438\u044f'
In [4]: print s.decode('unicode-escape')
Россия
In [5]: s2="Gigi D\u2019Agostino"
In [6]: s2
Out[6]: 'Gigi D\\u2019Agostino'
In [7]: print s2.decode('unicode-escape')
Gigi D’Agostino
You are using the cmd in Windows? In that case it might be a bit of a hack to get Unicode working at all to display correctly.
You might want to think about using another "terminal" to test your scripts.
MSYS provides a nice terminal/shell and IDLE is included in the Windows Python distribution and has a Python Shell (right click, open in IDLE, F5).
If you really want to make it work in the cmd:
You have to set Lucida Console as font in cmd. Then:
> chcp
Active code page: 850
> chcp 65001
Then you should have unicode output in the cmd. Your "Active code page" might be different. Note that somewhere, because you might want to change it back afterwards:
> chcp 850
Otherwise you will run into other problems (starting .bat files doesn't work).
(See also batch-file-encoding)
In your script you also need this:
import codecs
def cp65001(name):
"""This might be buggy, but better than just a LookupError
"""
if name.lower() == "cp65001":
return codecs.lookup("utf-8")
codecs.register(cp65001)
Otherwise python will crash. (see windows-cmd-encoding-change-causes-python-crash)
I had a similar bug report for my script.
You might also consider using a library to access the MusicBrainz Web Service.
Python-musicbrainzngs works with the current ws/2.
You should use json parser that returns Unicode string as any valid json parser does. Your failing example shows a bytestring i.e., you haven't used a json parser.
For example, to parse json data:
obj = json.load(urllib2.urlopen(request))
To pretty print obj without using Unicode escapes:
print json.dumps(obj, indent=4, ensure_ascii=False)
It is also useful to understand the difference between:
print unicode_string
And:
print repr(unicode_string)