python import arcpy not initialized runtime error - python-2.6

In my org we have issues of not having enough Arc licenses. I would like to be able to trap this, rather than have the python script blow up on me. My script bombs right at the import arcpy line when all licenses are in use. When there are licenses available, this works likes a charm.
here is the beginning of my script:
import os
import sys
import shutil
import arcpy
pathName = str(sys.argv[1])
print pathName
Here is the response:
Traceback (most recent call last):
File "C:\Dropbox\Work\EclipseSrc\src\arcMapScripts\dluProc\arcPyNad27toNad83_Auto.py", line 4, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 568, in <module>
env = GPEnvironments(gp)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 565, in GPEnvironments
return GPEnvironment(geoprocessor)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 521, in __init__
self._refresh()
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 523, in _refresh
envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized

I was experiencing this issue and the resolution for me revolved around scheduled tasks that were also executing at the time. Apparently with a Desktop Advanced License you cannot have two scripts running at the same time that both import arcpy. Once the scheduled task finished, I was able to execute my script with no problems.

You can use the CheckProduct function to check if licences are available. See this example copy/pasted from the Help page:
import sys
import arcpy
arcpy.env.workspace = "c:/data/world.gdb"
if arcpy.CheckProduct("ArcInfo") == "Available":
arcpy.PolygonToLine_management("Lakes", "LakeLines")
else:
msg = 'ArcGIS for Desktop Advanced license not available'
print(msg)
sys.exit(msg)

Related

ffmpeg-normalize exits with OSError: [WinError 193] %1 is not a valid Win32 application

I have a large number of files I want to normalize the volume with a simple method using a basic loop.
When trying to use ffmpeg-normalize the application exits with the error. I searched the error on-line but I can't find any issue similar to mine. I thought it may be a 'path' or file type association problem but they look ok.
Can anyone give me an explanation for this error and a possible fix for it please?
D:\Test>ffmpeg-normalize.exe in.mkv -o out.mkv
Traceback (most recent call last):
File "c:\users\les\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\les\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Les\AppData\Local\Programs\Python\Python39\Scripts\ffmpeg-normalize.exe\__main__.py", line 7, in <module>
File "c:\users\les\appdata\local\programs\python\python39\lib\site-packages\ffmpeg_normalize\__main__.py", line 409, in main
ffmpeg_normalize = FFmpegNormalize(
File "c:\users\les\appdata\local\programs\python\python39\lib\site-packages\ffmpeg_normalize\_ffmpeg_normalize.py", line 68, in __init__
self.has_loudnorm_capabilities = ffmpeg_has_loudnorm()
File "c:\users\les\appdata\local\programs\python\python39\lib\site-packages\ffmpeg_normalize\_cmd_utils.py", line 185, in ffmpeg_has_loudnorm
cmd_runner.run_command()
File "c:\users\les\appdata\local\programs\python\python39\lib\site-packages\ffmpeg_normalize\_cmd_utils.py", line 101, in run_command
p = subprocess.Popen(
File "c:\users\les\appdata\local\programs\python\python39\lib\subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "c:\users\les\appdata\local\programs\python\python39\lib\subprocess.py", line 1416, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
D:\Test>path
PATH=C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Calibre2\;C:\Program Files (x86)\Calibre2\;C:\Users\Les\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\Les\AppData\Local\Programs\Python\Python39\;C:\Users\Les\AppData\Local\Microsoft\WindowsApps;D:\MABS\local64\bin-video;C:\Program Files (x86)\sox-14-4-2
D:\Test>ftype python.file
python.file="C:\Users\Les\AppData\Local\Programs\Python\Python39\python.exe" "%1"
D:\Test>python.exe
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
ffmpeg -version
ffmpeg version N-100483-g728b83a7c4-gd67c6c7f6f+4 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
D:\Test>ffmpeg-normalize --version
ffmpeg-normalize v1.22.1
I had this exact same error. I had a ffmpeg version built using the "media-autobuild suite". Inside my ffmpeg install folder there was a standalone file named "ffmpeg". When typing "where ffmpeg" in the command prompt, it showed both "ffmpeg" and "ffmpeg.exe". The "ffmpeg" file is a bash script that I'm not sure what it does. I simply renamed the bash script file to something different and restarted my command prompt and the ffmpeg-normalize now worked without the error.

Volttron on MacOS issue with vcfg

Running into the issue below while trying to run vcfg command in Volttron on my Mac use iTerm. Any help would be much appreciated.
'''
(volttron)cg#Carolyns-MacBook-Pro volttron % vcfg
Your VOLTTRON_HOME currently set to: /Users/cg/.volttron
Is this the volttron you are attempting to setup? [Y]:
Message bus set to zmq
What is the vip address? [tcp://127.0.0.1]:
What is the port for the vip address? [22916]:
Is this instance web enabled? [N]: Y
Traceback (most recent call last):
File "/Users/cg/volttron/env/bin/vcfg", line 11, in <module>
load_entry_point('volttron', 'console_scripts', 'vcfg')()
File "/Users/cg/volttron/volttron/platform/config.py", line 593, in _main
main()
File "/Users/cg/volttron/volttron/platform/instance_setup.py", line 862, in main
wizard()
File "/Users/cg/volttron/volttron/platform/instance_setup.py", line 748, in wizard
do_web_enabled_zmq(volttron_home)
File "/Users/cg/volttron/volttron/platform/instance_setup.py", line 433, in do_web_enabled_zmq
'https://' + get_hostname())
File "/Users/cg/volttron/volttron/utils/__init__.py", line 27, in get_hostname
with open('/etc/hostname') as fp:
IOError: [Errno 2] No such file or directory: '/etc/hostname'
'''
/etc/hostname does not exist on Mac. The documentation for Volttron indicates that it only supports Linux operating systems.. It seems like you'll have to use a Linux host (or use virtualization).

Permission Denied While Accessing Files in Anaconda Prompt

I have a Python script that accesses some files, form example one line of code appends some text to a .txt file.
It runs correctly in a normal cmd.exe, with or without Admnistrator access. But while using a Anaconda Prompt or a cmd.exe opened from Anaconda Navigator it gives a PermissionError: [Errno 13] Permission denied: in the open('path/to/file', 'a+') line.
I'm looking for a solution for why Anaconda's python cannot access files. Another line of code using the function handlers.TimedRotatingFileHandler() from the logging module also throws the same error.
Some info that might be useful:
I have two Anaconda environments, one with python 2.7 and another one with python 3.6.6, both throw the error;
I have installed Anaconda 3 without adding anaconda to my PATH, because it was recommended in the installer;
My PATH's python, the version that works in the non-anaconda cmd.exe, is also 3.6.6;
I use Windows 10.
Edit:
Okay, so there seems to be some confusion about what I'm trying to accomplish. I'm making a text file with every .jpg file in a folder recursively, followed by the split of the file name. The text file should have: "path/to/XY_file_XY.jpg file" for every file found. Those splits represent the labels of the images for a neural network I'm training.
Here is my code for creating this text file:
import glob
class DBSetter(object):
def __init__(self, rootPath = 'C:\\Users\\Victor.Lundgren\\Google Drive\\Mestrado\\VC\\Projeto\\data\\mnt'):
self.path = rootPath
return
def setDB(self, extension = '.jpg', splitFileName = True, splitDilimiter = '_', splitPosition = 1):
query = self.path+'\\**\\*'+extension
print(query)
fileList = glob.glob(query, recursive = True)
sampleFileText = ''
for file in fileList:
word = file.split('\\')[-1]
if splitFileName:
word = word.split(splitDilimiter)[splitPosition]
sampleFileText += file+' '+word+'\n'
print('Sample File Text created.')
sampleFile = open(self.path+'\\sample.txt', 'a+')
sampleFile.write(sampleFileText)
sampleFile.close()
return
For instance, let's create a DBSetter object in a main.py and test ir with the default Python (3.6.6) in a simple cmd.exe and with Anaconda's Python (3.6.6) in an Anaconda Prompt:
from utils import database_setter
setter = database_setter.DBSetter('C:\\Users\\Victor.Lundgren\\Pictures\\Trabalho\\ASA') #choosing this folder for this example because it has few files in it.
setter.setDB(extension = '.png', splitFileName = False)
Here we have our cmd history in a simple cmd.exe calling main.py:
> Microsoft Windows [versão 10.0.16299.492] (c) 2017 Microsoft
> Corporation. Todos os direitos reservados. Clink v0.4.9 [git:2fd2c2]
> Copyright (c) 2012-2016 Martin Ridgers http://mridgers.github.io/clink
>
>
> C:\Users\Victor.Lundgren>cd C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto
>
> C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto>Python
> __main__.py C:\Users\Victor.Lundgren\Pictures\Trabalho\ASA\**\*.png Sample File Text created.
>
> C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto>
Now executing Anaconda Promp from the windows menu and runnning the same thing with my Python 3.6.6 env:
> Clink v0.4.9 [git:2fd2c2] Copyright (c) 2012-2016 Martin Ridgers
> http://mridgers.github.io/clink
>
>
> (base) C:\Users\Victor.Lundgren>cd C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto
>
> (base) C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto>activate Py3
>
> (Py3) C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto>Python
> __main__.py C:\Users\Victor.Lundgren\Pictures\Trabalho\ASA\**\*.png Sample File Text created. Traceback (most recent call last): File
> "__main__.py", line 6, in <module>
> setter.setDB(extension = '.png', splitFileName = False) File "C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto\utils\database_setter.py", line 19, in setDB
> sampleFile = open(self.path+'\\sample.txt', 'a+') PermissionError: [Errno 13] Permission denied:
> 'C:\\Users\\Victor.Lundgren\\Pictures\\Trabalho\\ASA\\sample.txt'
>
> (Py3) C:\Users\Victor.Lundgren\Google Drive\Mestrado\VC\Projeto>
After multiple attempts on reinstalling Anaconda I discovered the issue. My antivirus (Bitdefender) was exclusively blocking the Python version installed by Anaconda and for some reason not showing any notifications of it being blocked, removing the block made it run correctly.

Odoo10 Working setup now failing with ImportError: No module named conf

Working setup failing with ImportError: No module named conf
I stopped test setup on localhost with ^c to check logs
on restart I am getting error
C:\Odoo 10.0\server>odoo-bin -d todo -i todo_app --test-enable --dev=all
Traceback (most recent call last):
File "odoo-bin", line 2, in <module>
File "pkg_resources\__init__.pyc", line 2203, in declare_namespace
File "pkg_resources\__init__.pyc", line 2219, in declare_namespace
File "pkg_resources\__init__.pyc", line 2186, in _handle_ns
File "pkgutil.pyc", line 246, in load_module
argument should be the name of a package, in standard module format
File "C:\Odoo 10.0\server\odoo\__init__.py", line 61, in <module>
import conf
ImportError: No module named conf
TEST - Create folder conf with init.py from github
RESULT
C:\Odoo 10.0\server>odoo-bin -d todo -i todo_app --test-enable --dev=all
Traceback (most recent call last):
File "odoo-bin", line 2, in <module>
File "pkg_resources\__init__.pyc", line 2203, in declare_namespace
File "pkg_resources\__init__.pyc", line 2219, in declare_namespace
File "pkg_resources\__init__.pyc", line 2186, in _handle_ns
File "pkgutil.pyc", line 246, in load_module
argument should be the name of a package, in standard module format
File "C:\Odoo 10.0\server\odoo\__init__.py", line 61, in <module>
import conf
File "C:\Odoo 10.0\server\odoo\conf\__init__.py", line 15, in <module>
import deprecation
ImportError: No module named deprecation
CONCLUSION - Something happened to module conf - but I do not know what as I have made no such changes - John
I think you are using python 3.x .
this problem happened to me on linux but after using python 2.7.x it started as normal.

Python 3.4 and Windows Shared File Paths

I am trying to open a file in a shared network location
open('\\int\GroupData\ITProSup\Operations Support\REMGROUP.txt','+r')
Now this turns into
nemonics>python main.py
eback (most recent call last):
le "main.py", line 41, in <module>
sys.exit(main())
le "main.py", line 36, in main
insert_file_into_db(con_S104838,open('\\int\GroupData\ITProSup\Operations Su
t\REMGROUP.txt','+r'))
NotFoundError: [Errno 2] No such file or directory: '\\int\\GroupData\\ITPro
\Operations Support\\REMGROUP.txt'
I have tried this thread Using Python, how can I access a shared folder on windows network? but it does note seem to work for me. I am running python 3.4.1 and its windows 2012 server.
I have also tried using os.path https://docs.python.org/3.4/library/os.path.html#os.path.normpath with not much luck
C:\mnemonics>python main.py
Traceback (most recent call last):
File "main.py", line 41, in <module>
sys.exit(main())
File "main.py", line 36, in main
insert_file_into_db(con_S104838, open(os.path.normpath('\\int\GroupData\ITPr
oSup\Operations Support\REMGROUP.txt')))
FileNotFoundError: [Errno 2] No such file or directory: '\\int\\GroupData\\ITPro
Sup\\Operations Support\\REMGROUP.txt'
C:\mnemonics>python main.py
Traceback (most recent call last):
File "main.py", line 42, in <module>
sys.exit(main())
File "main.py", line 37, in main
open(os.path.normcase('\\int\GroupData\ITProSup\Operations Support\REMGROUP.
txt'),'+r'))
FileNotFoundError: [Errno 2] No such file or directory: '\\int\\groupdata\\itpro
sup\\operations support\\remgroup.txt'
Any help would be greatly appreciated
Note that \ should be escaped to \\, so \\ should be \\\\
Please try
'\\\\int\\GroupData\\ITProSup\\Operations Support\\REMGROUP.txt'
or
'//int/GroupData/ITProSup/Operations Support/REMGROUP.txt'

Resources