im useing Python (3.9) in combination with Microsoft Visual Studio Community 2019
Version 16.7.7
I try to use an example to write a config file. https://tutswiki.com/read-write-config-files-in-python/
Visual Studio is reporting me an syntax error at the keywords "open" an "as" and the ":" in the end of the line. Marks it red. There also is no highlight on the "with" and the "as" statement.
If i force Visual Studio to run anyway, it is running fine.
Does anyone know, what's the problem Visual Studio is reporting and how to fix it.
from configparser import ConfigParser
#Get the configparser object
config_object = ConfigParser()
#Assume we need 2 sections in the config file, let's call them USERINFO and SERVERCONFIG
config_object["USERINFO"] = {
"admin": "Chankey Pathak",
"loginid": "chankeypathak",
"password": "tutswiki"
}
config_object["SERVERCONFIG"] = {
"host": "tutswiki.com",
"port": "8080",
"ipaddr": "8.8.8.8"
}
#Write the above sections to config.ini file
with open('config.ini', 'w') as conf:
config_object.write(conf)
Thank you Silvio, you pushed me in the correct direction.
I added Python 3.9 (64Bit) to my project. While installation of Visual Studio i also selected the 64Bit version of Python3 (not the latest version available--> 3.7.8).
But Visual Studios installation path is:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
Because of the "(x86)" i tried to install the 32bit Python3 while installation of Visual Studio.
Now it works fine!
Related
OS: Windows 10
CMake: 3.18.2
MSVC: 16.7.3
When I use command line I can generate build with following line
cmake -B "D:\Builds" -S "D:\src" -G "Visual Studio 16 2019" -A "x64"
When I use followed Pytnon script:
subprocess.call([
'...\cmake.exe',
'-B "D:\Builds"',
'-S "D:\src"',
'-G "Visual Studio 16 2019"',
'-A "x64"'
])
I receive an error:
CMake Error: Could not create named generator "Visual Studio 16 2019"
Why it happens and how to fix it?
PS: this is not duplicate of any questions, this is new
Update1:
When I change generator line to the
'-G Visual Studio 16 2019'
I see the followed error:
CMake Error: Could not create named generator Visual Studio 16 2019
So I think it is not doublequotes fall
It looks like you may have two versions of CMake installed. Be sure the one used in your Python script is greater than or equal to CMake version 3.14. The Visual Studio 16 2019 generator is not available in earlier CMake versions.
You can test your CMake version used by the Python script by adding:
subprocess.call([
'...\cmake.exe',
'--version'
])
For me, a similar problem was resolved by removing the quotes within the quotes in Python, as hinted at in #Tsyvarev's comment above. IOW:
subprocess.call(['cmake', '-G', '"Visual Studio 16 2019"']) # Fails
subprocess.call(['cmake', '-G', 'Visual Studio 16 2019']) # Succeeds
Or if you want one generator arg:
subprocess.call(['cmake', '-G"Visual Studio 16 2019"']) # Fails
subprocess.call(['cmake', '-GVisual Studio 16 2019']) # Succeeds
I have a python script for a C++ project that uses CMake as the build system. I want to use the CMake Ninja generator instead of the Visual Studio generator. However, the Ninja generator expects the environment to be set up as performed by the vcvarsall.bat batch file provided with the Visual Studio installation.
It's easy if you do everything manually because you can just call the vcvarsall.bat file, get a command prompt with the correct environment set up and then you can fire the cmake -G Ninja command from there.
Things become more difficult when trying to use a python script that has not been started in such an environment. How do I call the vcvarsall.bat file programmatically from python, followed by a cmake call in that environment?
I assume that the only way is to just fire one subprocess from python. But I cannot come up with a parameter list that would do the job.
I'm lucky enough to have found an answer to my own question.
Here is the right python call to be used:
src_dir = ... # set your source dir here
build_dir = ... # set your build dir here
# retrieve visual studio installation path using vswhere.
# See: https://github.com/Microsoft/vswhere
vswhere = os.path.join(os.environ['ProgramFiles(x86)'],
"Microsoft Visual Studio",
"Installer",
"vswhere.exe")
# get installation path of Visual Studio 2017
vspath = subprocess.Popen([vswhere, "-property", "installationPath", "-version", "[15,16)"],
stdout=subprocess.PIPE).communicate()[0].rstrip()
# build path to vcvarsall.bat file
vcvarsall = os.path.join(vspath, "VC", "Auxiliary", "Build", "vcvarsall.bat")
# vcvarsall.bat changes the current directory to the one specified
# by the environment variable %VSCMD_START_DIR%
my_env = os.environ
my_env["VSCMD_START_DIR"] = build_dir
# set up the environment and then call cmake with Ninja generator
subprocess.call('call "' + vcvarsall + '" x64 && cmake -G Ninja "' + src_dir + '"', shell=True, env=my_env)
I am new to using Visual Code on Ubtuntu... But I followed all necessary instructions to install google app engine for python.
Then on writing my python code on the Visual Code, which I already modified my USER SETTINGS :
{
"python.autoComplete.extraPaths": [
"/usr/local/google_appengine",
"/usr/local/google_appengine/lib"],
"python.autoComplete.addBrackets": true,
"workbench.welcome.enabled": false,
"workbench.iconTheme": "vscode-icons",
"python.pythonPath": "/usr/bin/python",
}
Please how I can resolve this?
Add the following library paths to your "python.autoComplete.extraPaths" list:
"/usr/local/google_appengine/api",
"/usr/local/google_appengine/lib/webapp2-2.5.2"
I want to set up Visual Studio command line build environment with python so that I can use
subprocess.call(['msbuild', 'myapp.sln /p:Configuration=Release'])
to build my project with automation.
I have some other dependencies need to use a portable scripting language, so I chose python.
Is there any ways to do so? Thanks in advance.
Trial 1 (failure):
I tried to call vcvarsall.bat in python. However, it seems that it did not actually setup the environment for me.
import os
import subprocess
# Backup current environment vars
envvar_backup_list = [
'CMAKE_PREFIX_PATH',
'PATH'
]
envvar_backup_val_list = []
for i in envvar_backup_list:
envvar_backup_val_list.append(os.environ.get(i, None))
# Set CMAKE environment vars
os.environ['CMAKE_PREFIX_PATH'] = 'C:\\Qt\\Qt5.3.1\\5.3\\msvc2013_64\\lib\\cmake\\'
# Set MSVC environment path
current_path = os.getcwd()
os.chdir('C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\')
ret = subprocess.call(['vcvarsall.bat', 'amd64'], shell=True)
os.chdir(current_path)
subprocess.call(['msbuild'], shell=True)
subprocess.call(['cl.exe'], shell=True)
The command line instance that vcvarsall.bat and other commands run are not the same since each time you call subprocess.call() a new process is spawned, so that first call probably is initializing the build environment but then being killed. What you need to do is something like,
build = subprocess.Popen(['vcvarsall.bat', 'x86', '&&', 'msbuild', myProject.sln, '/p:Configuration=Release'])
build.wait()
if build.returncode != 0:
sys.exit("Build failed.")
PS: Reading vcvarsall.bat path from registry would be more portable, see the key SOFTWARE\\Microsoft\\VisualStudio\\<version>\\ShellFolder.
I'm trying to get the OpenERP server to build and run in Visual Studio 2012 using Python Tools for Visual Studio.
At the moment I get more than 2300 error messages, mostly along the lines of:
unexpected token 'x1'
I've downloaded the openerp-server-6.0.4 source and created a new Python project from Existing Python Code project in VS. I've selected the path to the OpenERP source(C:\OpenERP\Bin) when prompted and the file to execute when F5 is pressed is openerp-server.py. I've selected the Python 64-bit 3.3 interpreter.
The project is created, but even before building I receive the numerous unexpected token errors. For example in the account.py file it complain about an unexpected token 'tax' in the following code:
tax.type=='code':
address = address_id and obj_partener_address.browse(cr, uid, address_id) or None
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
exec tax.python_compute in localdict
amount = localdict['result']
data['amount'] = amount
When using TOOLS > Python Tools > Execute Project in Python Interactive I see the following result:
Python interactive window. Type $help for a list of commands.
Resetting execution engine
Interactive window is not yet started.
Running C:\temp\openerp-server-6.0.4\bin\openerp-server.py
Traceback (most recent call last):
File "C:\temp\openerp-server-6.0.4\bin\openerp-server.py", line 64, in
import tools
File "C:\temp\openerp-server-6.0.4\bin\tools__init__.py", line 23, in
import win32
ImportError: No module named 'win32'
Can anyone guide me into getting OpenERP to build and run using VS? Is it even possible?
Thank you!
You have to install
http://www.py2exe.org/index.cgi/PyOpenGL
Please try after install this module.