I'm trying to import a python file to my application which is written in python.  I have the following code:  import os from os.path import basename  class specificClass:     def dothing(self,path):           runcommand = __import__("/root/"+ os.path.splitext(os.path.basename(path))[0]+ "/" + os.path.splitext(os.path.basename(path))[0] +"/sa/update.py")           runcommand.main()   When I run it, it gives me the following error:  ImportError: Import by filename is not supported.
7325
How can I load a Python module given its full path? Note that the file can be anywhere in the filesystem, as it is a configuration option.
41476
I have written a script and am trying to run it in Python IDLE 2.7.6. I first try to import arcpy, but I get an error message saying:  ImportError: No module named arcpy  Why does it not work? I am using ArcGIS Desktop 10.2.
108844
I'm new to modelbuilder and python. I have used modelbuilder to iterate through all rows in a shapefile (Points), process them, and produce a seperate output shapefile for each row.  The filename is generated using an inline variable (I think that is the correct terminology).  i.e. all output files have identical filenames except that the value of the PointID from the original input file is appended to the filename to enable them to be distinguished.  This works fine.  I've also written a python script to take the above output files from the model one at a time and do additional processing.  At present the input filename is hard coded into the script (i.e. I have to edit the script to change the input filename each time I run it).  Again this works fine while just processing a single file. However, I want to integrate the model and the python script so that I can run the script for each row in the original feature class automatically.  My question is therefore, how do I replace the hard coded name of the input file with a variable in the python script and how do I pass the filename to the script.
87183
I am new to pythontex. I could run simple python code. However, I get error with slightly complex things.  The error I get is following:  This is PythonTeX 0.16  ----  Messages for py:default:default  ---- * PythonTeX stderr - error on line 211:     File "&lt;outputdir&gt;\py_default_default.py", line 62       MW= 18e-3 u.kilogram/ u.mole                 ^   SyntaxError: invalid syntax  -------------------------------------------------- PythonTeX:  notes - 1 error(s), 0 warning(s)  C:\texlive\2018\bin\win32\runscript.tlu:803: command failed with exit code 1: python.exe c:\texlive\2018\texmf-dist\scripts\pythontex\pythontex.py notes.tex   Part of the code that has error is :  \begin{pycode} import math from pint import UnitRegistry u = UnitRegistry() alpha = 0.04 sigmaW = 72.86e-3 * u.newton / u.meter mu    = 8.9e-4 * u.pascal * u.second densityW = 1000 * u.kilogram / (u.meter ** 3) densityIPA = 1000 * u.kilogram / (u.meter ** 3) densityEtoh = 1000 * u.kilogram / (u.meter ** 3) H = 1e-6 * u.meter W = 28e-6 * u.meter L= 32e-6 * u.meter MW= 18e-3 u.kilogram/ u.mole MIPA= 60.1e-3 u.kilogram/ u.mole MEtoh= 46.07e-3 u.kilogram/ u.mole R0=8.31446 u.joule / (u.mole * u.kelvin) T0= 298 u.kelvin N= 10 D0=2.4e-5 (u.meter ** 2)/(u.second) C0=17.08e-3 u.kilogram/(u.meter ** 3) tauevW=(densityW * N * R0 * T0 * (W **3))/(6* math.pi * D0 * C0 * sigmaW * MW) \end{pycode}   Does anyone know how to solve this issue?
1167
Python works on multiple platforms and can be used for desktop and web applications, thus I conclude that there is some way to compile it into an executable for Mac, Windows and Linux.  The problem being I have no idea where to start or how to write a GUI with it, can anybody shed some light on this and point me in the right direction please?
67428
How do I append a custom object from an external blender file using relative paths so I can pack the file with the addon? I can append the file easily with absolute path like this but I could fined how to do it with a relative path.   external blender file path ---> D:\blend_folder blender file name ---> external_blender_file.blend object name ---> object_2   This is using an absolute path:  # import bpy # bpy.ops.wm.append(filename="OBJECT_NAME", directory="/PATH/TO/BLENDFILE/NAME.blend\\Object\\")  import bpy bpy.ops.wm.append(filename="object_2", directory="D:/blend_folder/external_blender_file.blend\\Object\\")   How to make it work with a relative path?
37330
I am trying to get a number by counting how many points are in a shapefile. And this works, except I then am running into trouble using that number somewhere else. Eventually, I'll be using that count in some math (field calculator), but while debugging I'm running into an error that will end up causing me trouble later on.   This code:  TotalPoints = arcpy.GetCount_management(Path_Pts) arcpy.AddMessage("&gt;&gt;&gt;&gt; PROCESS: COUNT PATH POINTS {" + TotalPoints + "}")   gives this error:  TypeError: cannot concatenate 'str' and 'Result' objects   I tried casting it as a int, which it ALSO doesn't like:  TypeError: int() argument must be a string or a number, not 'Result'   So I've got a 'Result' object and need to turn it into a number.   How can I do that -- or is using the ArcPy function unnecessary or overly complicated here?
15517
I'm trying to set the documentclass type of a certain .tex file to be a class that is in the parent folder. However, I'm not sure how to include the path to the .cls file. I can write   \documentclass[letterpaper,12pt]{../foo}   But that complains that the imported class isn't the same as the provided class (in foo.cls I have \ProvidesClass{foo}. I know that this is just a warning and I could ignore it, or I could write \ProvidesClass{../foo}, but was wondering if there was a cleaner way to do the document class declaration.
44228
I am trying to run a standalone application. However, it does not run the program because of mentioned error in title. Here is my code:  from qgis.core import * from qgis.gui import * from qgis.utils import * from PyQt5.QtCore import * from PyQt5.QtGui import *  app = QgsApplication([], True) path = "C:/OSGeo4W64/apps/qgis-dev" app.setPrefixPath(path, True) app.initQgis()  canvas = QgsMapCanvas() title = "PyQGIS Standalone Application Example" canvas.setWindowTitle(title) canvas.setCanvasColor(Qt.white)  layer_info = 'LineString?crs=epsg:4326' layer = QgsVectorLayer(layer_info, 'MyLine', "memory") pr = layer.dataProvider() linstr = QgsFeature() wkt = "LINESTRING (1 1, 10 15, 40 35)" geom = QgsGeometry.fromWkt(wkt) linstr.setGeometry(geom) pr.addFeatures([linstr]) layer.updateExtents() QgsProject.instance().addMapLayer(layer)  canvas.setExtent(layer.extent()) canvas.setLayers([layer]) canvas.zoomToFullExtent() exitcode = app.exec_() QgsApplication.exitQgis() sys.exit(exitcode)   When I run it, I get this error:  Traceback (most recent call last):   File "C:/Users/DELL/Desktop/MyMap/myMap.py", line 1, in &lt;module&gt;     from qgis.core import *   File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\__init__.py", line 72, in &lt;module&gt;     from qgis.core import QgsFeature, QgsGeometry   File "C:\OSGeo4W64\apps\qgis-dev\python\qgis\core\__init__.py", line 34, in &lt;module&gt;     from qgis._core import *   ImportError: DLL load failed: The specified module could not be found.  Python version is: 3.6 PyQt   version is: PyQt5.9 Windows 10 - 64bit  I also add many path:  %SystemRoot%\system32 %SystemRoot% %SystemRoot%\System32\Wbem %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ C:\OSGeo4W64 C:\OSGeo4W64\apps C:\OSGeo4W64\apps\gdal-dev C:\OSGeo4W64\apps\gdal-dev\bin C:\OSGeo4W64\apps\gdal-dev\pymod3\Lib\site-packages C:\OSGeo4W64\apps\grass\grass-7.2.2\bin C:\OSGeo4W64\apps\Python36 C:\OSGeo4W64\apps\Python36\Scripts C:\OSGeo4W64\apps\Python36\DLLs C:\OSGeo4W64\apps\Python36\lib\site-packages C:\OSGeo4W64\apps\qgis-dev C:\OSGeo4W64\apps\qgis-dev\bin C:\OSGeo4W64\apps\qgis-dev\lib C:\OSGeo4W64\apps\qgis-dev\python C:\OSGeo4W64\apps\qgis-dev\python\qgis C:\OSGeo4W64\apps\Qt5 C:\OSGeo4W64\apps\Qt5\lib C:\OSGeo4W64\bin C:\OSGeo4W64\apps\qgis-dev\python C:\OSGeo4W64\apps\Python36\lib C:\OSGeo4W64\include C:\Users\Mustafa Uçar\AppData\Roaming\QGIS\QGIS3\profiles\default C:\Users\Mustafa Uçar\AppData\Roaming\QGIS\QGIS3\profiles\default\QGIS   How can I fix this error?
27101
I have Ubuntu 14.04 with python-2.7 and python-3 support. I am porting my python application from python-2.7 to python-3. I have example.py file which is importing below modules. and I #!/usr/bin/python3 as python evn variable.  import gtk, gobject, time, sys, os, subprocess, signal   **ImportError: No module named 'gtk'**   I am getting above error, when trying to run with python3.  Any idea what is missing here?
18926
I'm trying to understand the use of super(). From the looks of it, both child classes can be created, just fine.   I'm curious to know about the actual difference between the following 2 child classes.  class Base(object):     def __init__(self):         print "Base created"  class ChildA(Base):     def __init__(self):         Base.__init__(self)  class ChildB(Base):     def __init__(self):         super(ChildB, self).__init__()  ChildA()  ChildB()
65641
I have a fresh install of TeX Live 2013 and am attempting to compile a file using the python package. Here is the relevant portion of the file  \begin{python} print 'hi' \end{python}   I've compiled successfully on my linux machine with TeX Live 2013, but cannot get my windows 7 machine to compile successfully. When I run latex --shell-escape pytest.tex I get an error which begins with   pytest.py: Forbidden to open for writing ! I can't write on file `pytest.py'. \@python ...mediate \openout \@out =\@outname .py                                                    \newlinechar ='15 \begingr...   Can anyone help me fix this so I can compile latex documents using python.sty on my windows machine?  Update  So I'm pretty certain the issue has to do with permissions. If that is the case it would be really great if there were a few easy tests I could run to determine why \write18 cannot open files for writing / what it is trying to do. I've seen some problems from searching that were related to the TEXMFOUTPUT environment variable, but I don't know (1) what to set as the value of TEXMFOUTPUT in order to make sure that these temporary python files are created in the current working directory and (2) if setting TEXMFOUTPUT would have anything to do with these \write18 permission problems.  Ok, one new piece of information: So, I've created a minimal example:  \documentclass[letterpaper,10pt]{article} \usepackage{python} \begin{document}  \begin{python} print 'hi' \end{python}  \end{document}    When compiled after the `! I can't write on file pytest1.py' It says (Press Enter to retry, or Control-Z to exit; default file extension is '.tex' Is this error because write18 can only write to a .tex file?  At the beginning of the compile on the second line it just says ` \write18 enabled'. So it is not running with restricted \write18. I feel like I am really close to fixing this.  Solved  The comment  was exactly right. I had .py listed in my PATHEXT environment variable. Removing it allowed the file to compile without error.  Just read meta.tex.SE and will credit JosephWright once answer is up.
14438
Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load JAR files dynamically. I'm told there's a way of doing it by writing your own ClassLoader, but that's a lot of work for something that should (in my mind at least) be as easy as calling a method with a JAR file as its argument.  Any suggestions for simple code that does this?
32948
I have a function that resembles the one below. I'm not sure how to use the os module to get back to my original working directory at the conclusion of the jar's execution.   def run():      owd = os.getcwd()     #first change dir to build_dir path     os.chdir(testDir)     #run jar from test directory     os.system(cmd)     #change dir back to original working directory (owd)   note: I think my code formatting is off - not sure why. My apologies in advance
44188
The path for the Python executable used in Blender (up to 2.79) is not configurable.  I looked around and did not find a consistent way to be able to use custom  3rd party Python modules without installing then directly in the O.S. Python.  This would work, although not the ideal solution, but then I had issues with that in Linux, as running pip install system wide adds the modules to /usr/local/lib, but /usr/local is not the in the PYTHONPATH when Blender is started.   An active Python virtualenv - Python's own way of isolating 3rd party modules is ignored by Blender - as the way to activate a virtualenv is simply using it's Python binary (in a different Path than the one used by Blender).
78790
I'm using Ubuntu 11.10.  The python 2.7.2 provided has a bug that has been corrected in the latest 2.7.2 sources from the python repository.  What is the recommended way to replace the ubuntu provided python with the python from source? Or put another way, how do I "update" the ubuntu-provided one?  Ideally, I would just be able to create new .deb(s) that "update" the python2.7/python2.7-dev provided by Ubuntu.
61815
I read the Java tutorials on Sun for JAR files, but I still can't find a solution for my problem. I need to use a class from a jar file called jtwitter.jar, I downloaded the file, and tried executing it (I found out yesterday that .jar files can be executed by double clicking on them) and Vista gave me an error saying "Failed to load Main-Class Manifest attribute from [path]/jtwitter.jar".  The guy who coded the .jar file wants me to import it, but where do I store the .jar file to import it in my code? I tried putting both the .jar file and my .java file in the same directory, didn't work.  The file I'm trying to work for is here:   I'm using JCreator LE.