I have been trying to make a program launch on starting my system.
here is my problem..
ulogme (https://github.com/karpathy/ulogme) is a personal time tracker.
But after installation it needs to launched every time by running
$ python ulogme_serve.py
I want this script to run automatically on startup.
Solution by Atto Allas works well.
I am facing a new problem now,
I keep getting the following error
*
* Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
main()
File "/usr/lib/python3.5/site.py", line 566, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'**
Any suggestion and help are welcome
Thanks in Advance
If you want it to run at login
https://askubuntu.com/questions/48321/how-do-i-start-applications-automatically-on-login
Step 1: In the dashboard, search for 'startup applications'
Step 2: In the preferences screen that comes up, click 'add'
Step 3: Choose a name (for example, 'Ulogme Tracker'), a command to run (python ulogme_serve.py) and a comment ('Personal time tracker')
Step 4: Finally, click 'add'.
This should make it so that any time you log in, it will start ulogme_serve.py.
If you want it to run at system startup
https://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/
Step 1: Create a shell script called ulogme_startup.sh by typing sudo nano /etc/init.d/ulogme_startup.sh in terminal
Step 2: In the editor, type python ulogme_serve.py
Step 3: Hit 'ctrl+x' then 'y' and then hit 'enter'
Step 4: Back at the terminal, type sudo update-rc.d ulogme_startup.sh defaults
Step 5: Finally type sudo chmod +x ulogme_startup.sh
This should now run at system startup.
I hope this helps!
N.B. This will only work if ulogme_serve.py is on your path, if it isn't, change all instances of ulogme_serve.py to its absolute filepath. For example, if it was in a folder called 'ulogme' in your home folder, you would replace ulogme_serve.py with /home/<your username>/ulogme/ulogme_serve.py.
Related
I was forced into some software updates on my laptop (ThinkPad) and after the update when I tried to open Spyder (via Anaconda) and it won't open. I don't have any experience in errors like this or fixing this stuff (and I am aware this may be something that is super simple). Please help. This is the application launch error I am getting:
Traceback (most recent call last):
File "C:\Users\cyrra\anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3651, in main
mainwindow = run_spyder(app, options, args)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3526, in run_spyder
main.setup()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 871, in setup
self.help = Help(self, css_path=css_path)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\plugins\help\plugin.py", line 68, in __init__
color_scheme = self.get_color_scheme()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\api\plugins.py", line 347, in get_color_scheme
return super(BasePluginWidget, self)._get_color_scheme()
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\plugins\base.py", line 446, in _get_color_scheme
return get_color_scheme(CONF.get('appearance', 'selected'))
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\gui.py", line 114, in get_color_scheme
color_scheme[key] = CONF.get("appearance", "%s/%s" % (name, key))
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\manager.py", line 228, in get
return config.get(section=section, option=option, default=default)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py", line 976, in get
return config.get(section=section, option=option, default=default)
File "C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py", line 513, in get
raise cp.NoOptionError(option, section)
configparser.NoOptionError: No option 'custom-1/background' in section: 'appearance'
Thanks,
Rachel
Did you try to run spyder on the terminal?
It should be prebuild in Anaconda.
Your Spyder config file should contain but is missing 'custom-1/background' in section: 'appearance'. If you have no experience, the easiest thing for you to do is uninstall and install Spyder (via Anaconda). Your other option is to find the config file called in line 513 of C:\Users\cyrra\anaconda3\lib\site-packages\spyder\config\user.py". Then open the config file (if it exists) and correct it. If the file is not found, search for that config file and place it in the expected location.
I'm trying to use dask from Pycharm using a remote (SSH) interpreter.
Here's some code:
from dask.distributed import Client
client = Client(processes=True)
On Python 2 this seems to work fine, but on Python 3 this fails with:
Traceback (most recent call last):
File "/usr/lib/python3.8/multiprocessing/forkserver.py", line 278, in main
code = _serve_one(child_r, fds,
File "/usr/lib/python3.8/multiprocessing/forkserver.py", line 317, in _serve_one
code = spawn._main(child_r, parent_sentinel)
File "/usr/lib/python3.8/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/usr/lib/python3.8/multiprocessing/spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/usr/lib/python3.8/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/usr/lib/python3.8/runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "/usr/lib/python3.8/runpy.py", line 231, in _get_code_from_file
with open(fname, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/<input>'
distributed.nanny - WARNING - Restarting worker
/home/ubuntu exists and is writable- I'm not sure what /home/ubuntu/input is though!
Does anyone have an idea as to what is going wrong here?
EDIT
so after a bit of tracing back I can see that in multiprocess/spawn.py on line 226, there is a prepare function which takes a map of properties describing the processed to be spawned. For some reason the 'init_main_from_path' in that map is being set to /home/ubuntu/<input> which is a directory that doesn't exist anywhere (I'm not even usre this is a valid directory name!). It looks like the PyCharm console is setting this to help itself with the remote execution, but it's messing up the ability of multiprocess to correctly spawn a process. If I hack multiprocess/spawn.py to remove the rogue 'init_main_from_path' key then I can start the client.
I am really quite new to development in Python in general, let alone testing with pytest. My problem is that the pytest collection phase runs unusually slow. I am specifying the test directory which contains only a handful of files with only one file containing three tests. The collection takes pretty much a whole minute, after which the actual tests run in under a few seconds. I have looked at similar questions but couldn't find a solution. I don't think it matters (as py.test is slow even from the command line) but I am using the pycharm IDE. The OS is Ubuntu.
This may be relevant: If I terminate the process after a few seconds I usually end up with a stacktrace ending as follows:
<A FEW LINES OMITTED...>
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 413, in __call__
return self._docall(methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 424, in _docall
res = mc.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 27, in pytest_cmdline_parse
config = __multicall__.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 636, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 747, in parse
self._preparse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 709, in _preparse
self._initini(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 704, in _initini
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 861, in getcfg
if exists(p):
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 848, in exists
return path.check()
File "/usr/local/lib/python2.7/dist-packages/py/_path/local.py", line 352, in check
return exists(self.strpath)
File "/usr/lib/python2.7/genericpath.py", line 18, in exists
os.stat(path)
KeyboardInterrupt
Or sometimes...
<STACK TRACE...>
File "/usr/local/lib/python2.7/dist-packages/py/_iniconfig.py", line 50, in __init__
f = open(self.path)
KeyboardInterrupt
Maybe one of the two last calls before the KeyboardInterrupt is very slow?
Please do ask for more detail should you require it!
Cheers!
Add PYTHONDONTWRITEBYTECODE=1 to your environment variables!
Windows Batch: set PYTHONDONTWRITEBYTECODE=1
Unix: export PYTHONDONTWRITEBYTECODE=1
subprocess.run: Add keyword env={'PYTHONDONTWRITEBYTECODE': '1'}
Note that the first two options are only valid for your current terminal session.
Here is how I found this out: pytest was being unusably slow from the command line, but working fine from within PyCharm. Copying the PyCharm command into cmd.exe (executes a small helper script) also was unusuably slow. Thus I printed out the environ variables at os.environ and tried it with that -- and it was fast! Then I eliminated each one-by-one.
I had the same problem. My fix was to set the Working directory setting in the Run/Debug Configuration to the folder where manage.py is located.
My solution was based off of this answer, where I did pytest dir/to/tests and it skipped the collection step entirely.
I am a newbie to py.test , Please let me know how to run the py.test in PyScripter Editor.
I have tried in the belwo way but it doesn't work.
import pytest
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
pytest.main()
and on running the above script i get an error saying
Traceback (most recent call last):
File "<module1>", line 10, in <module>
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 474, in main
exitstatus = config.hook.pytest_cmdline_main(config=config)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 107, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 92, in wrap_session
config.pluginmanager.notify_exception(excinfo, config.option)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 285, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 152, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 140, in write_line
self._tw.line(line, **markup)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 181, in line
self.write(s, **kw)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 225, in write
self._file.write(msg)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 241, in write
self._writemethod(data)
TypeError: 'AsyncStream' object is not callable
Pleae do help me
The script appears to be wrong , as far as i know pytest.main can be used if you want your pytest should be run by python interpreter. You need have have your test under a directory.
For example your pytest file is called test_sample which has following content
===================================pytests/test_sample===============================
import pytest
def func(x): return x + 1
def test_answer(): assert func(3) == 5
==================================================================================
Then you can have the following code in python file which runs your test_sample
pytest.main(args=['-s', os.path.abspath('pytests')])
This should solve your problem
If you dont want python to run your pytests you can configure pyscripter runner to be run by pytests via tools-->configure tools and then add the pytests command line argument. you can then run you pytest from tools. By default pyscripter uses python interpreter as runner
You can use pytest in pydev :
http://pypi.python.org/pypi/pytest-pydev/0.1
Seems like PyScripter sets some sys.stdout stream that pytest does not recognize. I just tried to refine the handling from pytest's side. You can try using it with:
pip install -i http://pypi.testrun.org -U pytest
which should in particular install also the "py" lib which contains the TerminalWriting code. If that doesn't work, please file an file with the exact environment/PyScripter version you are using. And also the value of "import py ; print py.version".
HTH,
holger
import pytest,os
os.chdir("C:\Users\Public\Documents\Development\Python\<test_pytest.py>") #your file location
pytest.main(['-s', 'test_pytest.py'])
save the file . On Pyscripter go to Run-->Python Engine--> Internal
Run the test , it should work.
Somtime pyscripter doesn't pick up the change, you may have to reinitialise the python engine (Ctrl+F2)
I am relatively new to Python, and at the same time, am attempting to install mod_dav_svn into my Apache web server. I am looking to get some idea of the scope of the error I'm receiving.
At the command line, I type in 'sudo yum install mod_dav_svn' and receive this output:
Loaded plugins: fastestmirror
Determining fastest mirrors
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 229, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 104, in main
result, resultmsgs = base.doCommands()
File "/usr/share/yum-cli/cli.py", line 339, in doCommands
self._getTs(needTsRemove)
File "/usr/lib/python2.4/site-packages/yum/depsolve.py", line 101, in _getTs
self._getTsInfo(remove_only)
File "/usr/lib/python2.4/site-packages/yum/depsolve.py", line 112, in _getTsInfo
pkgSack = self.pkgSack
File "/usr/lib/python2.4/site-packages/yum/init.py", line 591, in
pkgSack = property(fget=lambda self: self._getSacks(),
File "/usr/lib/python2.4/site-packages/yum/init.py", line 434, in _getSacks
self.repos.populateSack(which=repos)
File "/usr/lib/python2.4/site-packages/yum/repos.py", line 223, in populateSack
self.doSetup()
File "/usr/lib/python2.4/site-packages/yum/repos.py", line 71, in doSetup
self.ayum.plugins.run('postreposetup')
File "/usr/lib/python2.4/site-packages/yum/plugins.py", line 176, in run
func(conduitcls(self, self.base, conf, **kwargs))
File "/usr/lib/yum-plugins/fastestmirror.py", line 181, in postreposetup_hook
all_urls = FastestMirror(all_urls).get_mirrorlist()
File "/usr/lib/yum-plugins/fastestmirror.py", line 333, in get_mirrorlist
self._poll_mirrors()
File "/usr/lib/yum-plugins/fastestmirror.py", line 376, in _poll_mirrors
pollThread.start()
File "/usr/lib/python2.4/threading.py", line 416, in start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread
The only other question I could find with a similar error was this one: https://stackoverflow.com/search?q=can%27t+start+new+thread+python, but I'm not sure it has to do with running too many threads since I am the only one using the server, and this is one of the first python commands I have used. Could someone point me in the right direction, or towards some material that may help me troubleshoot the issue? Thanks!
Disable yum-fastermirror and you should be able to complete the install.
yum --disableplugin=fastestmirror update
Are you on a virtual machine?