I tried using bitmex-market-maker python package.
Here's how to use this package.
Install: pip install bitmex-market-maker. It is strongly recommeded to use a virtualenv.
Create a marketmaker project: run marketmaker setup
I learned how to make my own command-line commands using python here.
To make my own commands, however, I had to type several terminal commands like
$ chmod +x marketmaker.py
$ mv marketmaker.py marketmaker
$ mkdir -p ~/bin
$ cp marketmaker ~/bin
$ export PATH=$PATH":$HOME/bin"
But I didn't type this commands at all but only installed bitmex-market-maker package using pip.
Can you help me figuring out how things work behind the scene?
I post marketmaker codes.
#!/usr/bin/env python
from market_maker import market_maker
market_maker.run()
Related
I would like to use the python3 executable when I use it from crontab as manual launch (ssh session).
bash script
#!/bin/bash
PYTHONPATH="$(which python3)"
echo $PYTHONPATH
python3 test.py
result from ssh command line, launched manually
/usr/local/bin/python3
result in log file from crontab -e
/usr/bin/python3
I would like the script launched by the crontab, uses /usr/local/bin/python3 executable instead of /usr/bin/python3
OR
if it's not possible, use the dependencies of my code available for /usr/bin/python3
How can I achieve this ? Thank you very much for your help
the python inside the docker container will not necessarily have the same path. If you want all the modules installed on your VM python3, create a requirements.txt file using pip freeze > requirements.txe and COPY this file as part of your Dockerfile and install it while building the image pip install -r requirements.txt
I'm trying to automate the deployment of my Python-Flask app on Ubuntu 18.04 using Bash by going through the motion of preparing all the necessary files/directories and cloning the source code from Github followed by creating the virtual environment, installing the pre-requisite modules and etc.
Now because I have to execute my Bash script using sudo, this means that the entire script will be executed as root except where I specify otherwise using sudo -u myuser and when it comes to activating my virtual environment, I get the following output: sudo: source: command not found and my subsequent pip installs are all installed outside of the virtual environment. Excerpts of my code below:
#!/bin/bash
...
sudo -u "$user" python3 -m venv .env
sudo -u $SUDO_USER source /srv/www/www.mydomain.com/.env/bin/activate
sudo -u "$user" pip install wheel
sudo -u "$user" pip install uwsgi
sudo -u "$user" pip install -r requirements.txt
...
Now for the life of me, I can't figure out how to activate the virtual environment in the context of the virtual environment if this makes any sense.
I've scoured the web and most of the questions/answers I found revolves around how to activate the virtual environment in a Bash script but not how to activate the virtual environment as a separate user within a Bash script that was executed as sudo.
That's because source is not an executable file, but a built-in bash command. It won't work with sudo, since the latter accepts a program name (i.e. executable file) as argument.
P.S. It's not clear why you have to execute the whole script as root. If you need to execute only a number of commands as root (e.g. for starting/stopping a service) and run a remaining majority as a regular user, you can use sudo only for these commands. E.g. the following script
#!/bin/bash
# The `whoami` command outputs the current username. Unlike `source`, this is
# a full-fledged executable file, not a built-in command
whoami
sudo whoami
sudo -u postgres whoami
on my machine outputs
trolley813
root
postgres
P.P.S. You probably don't need to activate an environment as root.
I have the problem that when I run my code on a linux server I get:
ModuleNotFoundError: No module named '_sqlite3'
So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't.
I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide.
All solutions to this sqlite3 problem that I can find requires sudo commands.
Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?
I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
While installing a python package in a Linux system without "sudo" privileges you can use
For Python 3
pip3 install --user pysqlite3
You can install any third party packages with the same method
pip3 install --user PACKAGE_NAME
The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, #Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install
$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install
$ ~/applications/bin/python
Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/
I tried following the documentation, which can be found here: (https://pythonhosted.org/wheezy.web/gettingstarted.html) but I'm too dumb to figure it out.
Install
Wheezy Web requires python version 2.4 to 2.7 or 3.2+. It is independent of operating system. You can install it from pypi site using setuptools:
$ easy_install wheezy.web
If you are using virtualenv:
$ virtualenv env
$ env/bin/easy_install wheezy.web
Since Wheezy Web is template engine agnostic, you need specify extra
requirements (per template engine of your choice):
$ env/bin/easy_install wheezy.web[jinja2]
$ env/bin/easy_install wheezy.web[mako]
$ env/bin/easy_install wheezy.web[tenjin]
$ env/bin/easy_install wheezy.web[wheezy.template]
Develop
You can get the source code using mercurial:
$ hg clone http://bitbucket.org/akorn/wheezy.web
$ cd wheezy.web
Prepare virtualenv environment in env directory
$ make env
... and run all tests:
$ make test
You can read how to compile from source code different versions of python in the article published on mind reference blog.
You can run certain make targets with specific python version. Here we are going to run doctest with python3.2:
$ make env doctest-cover VERSION=3.2
Generate documentation with sphinx:
$ make doc
Source: https://pythonhosted.org/wheezy.web/gettingstarted.html#install
If it's still actual, you can install wheezy.web just via pip: pip install wheezy.web wheezy.template
Two questions:
Is there a Python equivalent to forever.js to run a Python process in the background without requiring sudo?
Is it possible to use forever.js with Python? How about with a virtualenv?
It is easy to use Python with forever.js:
forever start -c python python_script.py
To use it with virtualenv is a little bit more complicated, I did it using a bash script (call it python_virtualenv):
#!/bin/bash
# Script to run a Python file using the local virtualenv
source bin/activate
bin/python $#
Now use that script with forever:
forever start -c ./python_virtualenv python_script.py
I was having problems executing a python script with custom logging paths, after trying I got to work with the next command:
forever start -c python -l /tmp/forever.log -o /tmp/out.log -e /tmp/error.log python_script.py
Tell me if it worked for you
Using python 3 with Flask to run with forever.js, here is my build process
python3 -m venv venv
source venv/bin/activate
sudo -H pip3 install -r requirements.txt
FLASK_APP=app.py forever start -c python3 app.py --port=5001