cant run file with sys.argv - argv

I'm unable to go ahead. please help.
this is a link for the code i used
i tried downloading the module using cmd windows 10 but that is also showing an error...
C:\Users\kayza\Desktop\image_converter>python jpgtopng.py jpeg png
Traceback (most recent call last):
File "jpgtopng.py", line 5, in
image_input = sys.argv1
NameError: name 'sys' is not defined

The problem is that you import every module from the package sys. Because of that you can't access them with the dot notation (sys.argv[]).
You have two options to fix this.
Access the method like this argv[] without the sys. in front of it.
(the cleaner option)
Change your import statement to import sys

Related

Import script in sub directory not working... Blender Add-On

I have a folder structure like this:
C:
|_Blueprint
│ main.py
│
└───toolbox
blueprint_tools.py
When I run this code in Blender's scripting text page:
from toolbox.blueprint_tools import dimension, array, modify
I get an error in the console
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ModuleNotFoundError: No module named 'toolbox'
Error: Python script failed, check the message in the system console
I swear, when I run this code (on other projects) outside of Blender this structure and code runs fine. But I get an error when running this script in Blender for testing out my Add-On.
If I compile the Blueprint folder into a .zip and install it everything works fine.... ??
I'm lost, could anyone please help me.
If I run the code like this: (added a . before toolbox for CWD)
from .toolbox.blueprint_tools import dimension, array, modify
Traceback (most recent call last):
File "\main.py", line 20, in <module>
ImportError: attempted relative import with no known parent package
Error: Python script failed, check the message in the system console
Both your error traces write File \main.py ... which means that Blender considers your main.py file to be in the root folder, knowing nothing about its real location in the file system hierarchy.
When you installed your structure as a zip file, you provided all necessary info to Blender.
Addendum:
Temporarily, during developing / debugging your add-on, you may add the full path (for finding your toolbox.blueprint_tools module) to the sys.path variable.
There are 2 possibilities how to do it:
Insert into your main.py file these commands (use the path to your parent folder of your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox"]
before your statement
from toolbox.blueprint_tools import dimension, array, modify
command, or
Insert into your main.py file these commands (use the path to your toolbox folder, of course):
import sys
sys.path += [r"C:\Users\Davi\Documents\Python\PARENT_of_toolbox\toolbox"]
before your modified statement
from blueprint_tools import dimension, array, modify

Unable to run python code from Linux command line

I have gone through the explanations given in this forum and have tried them in my program. However, none of the suggestions worked. That's why I am opening this thread.
Below is the tree for my project. There are 2 packages: com and main.
When I try to run the code for ProcessRiskModelbyRecordID.py from command line, I am getting below error message:
$ python3 /AppDev/XXXX/py/riskScore/main/ProcessRiskModelbyRecordID.py
Traceback (most recent call last):
File "/AppDev/XXXX/py/riskScore/main/ProcessRiskModelbyRecordID.py", line 6, in
from main.ConnectAPI import *
ModuleNotFoundError: No module named 'main'
When I run the same code from PyDev, I am able to execute it.
Below is the import code from ProcessRiskModelbyRecordID.py:
from main.ConnectAPI import *
from com import DBOperations as DBO,SourceProfile,TargetProfile
Can you please help so that I can run this code from command line?
PyDev is probably setting PYTHONPATH for you. On the command line you would need to set it yourself:
cd riskScore
export PYTHONPATH=`pwd`
python3 main/ProcessRiskModelbyRecordID.py

Splinter (python library) import not being recognized

My code begins as follows:
from splinter import Browser
executable_path = {'executable_path': 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'}
with Broswer('chrome', **executable_path) as browser:
This is how it begins on splinter's own documentation. I've also tried this without the parameters for Browser, still nothing.
When I run this file, I get the following error:
Traceback (most recent call last):
File "getBookData.py", line 5, in <module>
with Broswer() as browser:
NameError: name 'Broswer' is not defined
I've installed splinter, I'm importing Browser; I can't find anything on this error and I have no idea what's causing it. Anyone know what to do?

Zipline import error. No module named zipline.transforms

I am not able to import the zipline.transforms module
>>> from zipline.transforms import batch_transform
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'zipline.transforms'
Disclaimer: I'm currently a maintainer of Zipline.
I'm guessing the reason you're seeing this error is because that particular module was removed a while back (assuming you're using zipline 1.0.0 or later). If you want to do things similar to transforms you'll need to call data.history() to get your pricing data, and call numpy/pandas functions like .avg() or .std(), or use talib.
I think you should firstly print out your sys.path (print sys.path), and then see where you zipline module is installed (somewhere like .../lib/python2.7/site-packages/zipline). Usually "no module named XXX" is caused by you sys.path doesn't contain the path you installed zipline. You should just add your zipline path into sys.path. Also use anaconda is good for zipline (http://www.zipline.io/install.html), so as to keep the environment tidy and clean.

How do I install delayedresult module in wxPython

I have installed and used wxPython on my work pc (using threading in many apps). However, I attempted to set-up the same environment on my personal computer, and I cannot get the module lib.delayed result to run for anything. I can use wxPython with my applications that don't use threading, but when I attempt to run any app that uses threading, I get the following traceback:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import lib.delayedresult
ImportError: No module named lib.delayedresult
I've exhausted what I know to do, at this point .... I appreciate any help/direction in advance.
I am using it by importing like:
import wx.lib.delayedresult as delayedresult

Resources