I want to apply python subprocess to follow three commands but I am failing to do so? - subprocess

The three commands are :
Start the Virtual Environment by this command - source Detect_Outliers_In_Dataset/bin/activate
Change the directory by this command - cd Outlier_Detection
Start running Django Server by this command - python3 manage.py runserver
import subprocess
import pdb
p1 = subprocess.run("source Detect_Outliers_In_Dataset/bin/activate | cd Outlier_Detection | python3 manage.py runserver", capture_output=True, text=True, shell=True)
This is the error :
ompletedProcess(args='source Detect_Outliers_In_Dataset/bin/activate | cd Outlier_Detection | python3 manage.py runserver', returncode=2, stdout='', stderr="/bin/sh: 1: source: not found\n/bin/sh: 1: cd: can't cd to Outlier_Detection\npython3: can't open file 'manage.py': [Errno 2] No such file or directory\n")

Related

CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files

I'm trying to run linux docker on windows and getting this error.
build was fine.
'''
$ docker-compose build
Building web
Step 1/11 : FROM python:3
---> 42d620af35be
Step 2/11 : ENV PYTHONUNBUFFERED 1
---> Using cache
---> b43065732d6e
Step 3/11 : RUN apt-get update -y
---> Using cache
---> 6f65e0da9e14
Step 4/11 : RUN apt-get install -y unixodbc unixodbc-dev
---> Using cache
---> 2a9d7445a991
Step 5/11 : RUN easy_install pip
---> Using cache
---> 5994e6452e09
Step 6/11 : RUN mkdir /code
---> Using cache
---> d0eaa870fb98
Step 7/11 : WORKDIR /code
---> Using cache
---> af78d4b35f26
Step 8/11 : RUN pip uninstall django
---> Using cache
---> 92f983bfef88
Step 9/11 : COPY requirements.txt /code/
---> Using cache
---> 3c0031987286
Step 10/11 : RUN pip install -r requirements.txt
---> Using cache
---> 3915127d3d58
Step 11/11 : COPY . /code/
---> Using cache
---> de872685c733
Successfully built de872685c733
Successfully tagged djangoproject_web:latest
'''
but when i run compose up.. i see below error.
'''
$ docker-compose up
Creating djangoproject_web_1 ... done
Attaching to djangoproject_web_1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | July 23, 2019 - 03:21:21
web_1 | Django version 2.2.3, using settings 'composeexample.settings'
web_1 | Starting development server at http://case.xxxxxx.com:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | Error: [Errno -2] Name or service not known
djangoproject_web_1 exited with code 1
'''
and if i try this
'''
docker-compose run web django-admin startproject composeexample .
'''
it says
'''
CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files
'''
my Dockerfile is
'''
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN apt-get update -y
RUN apt-get install -y unixodbc unixodbc-dev
RUN easy_install pip
RUN mkdir /code
WORKDIR /code
RUN pip uninstall django
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
'''
my docker-compose.yml is
'''
version: '3'
services:
web:
build: .
command: python manage.py runserver case.xxxxxx.com:8000
volumes:
- .:/code
ports:
- "8000:8000"
'''
How can i fix the problem with composeexample? it is not even created (cause i can't see it in the folder).. your advice please.
You are probably using the docker client of Ubuntu Windows Subsystem. This gives issues with Volume feature of docker.
Run the docker run command on windows powershell and this issue will not come.
This error occurs if you try to create another project in a single virtual environment. To remove error and create next project delete "manage.py file" which is the file automatically created while starting project.
If you still get error delete the virtual environment and delete manage.py
You have 2 conflicting/overwriting statements:
In your Dockerfile:
COPY . /code/
in your docker-compose.yml:
volumes:
- .:/code
I suggest you remove the COPY statement from the Dockerfile and re-run your containers using docker-compose.
Also, you can remove the RUN command here:
RUN mkdir /code
WORKDIR /code
It is not an error, but WORKDIR already creates the folder if it doesn't exist anyway.
The problem is, you are trying to create a project that is already created by re-running the command
docker-compose run web django-admin startproject composeexample .
Just run
docker-compose run web

jupyterlab/hub-extension#0.12.0" is not compatible with the current JupyterLab

I want to install the littlest jupyterhub via .gitlab-ci.yml in a subdomain.
Here is my .gitlab-ci.yml. I get this error message. I need a little help to fix this error message. I know the littlest jupyterhub is still in beta.
Is it possible to add packages like pandas, mathplotlib to install with a shell script?
$ curl https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/bootstrap/bootstrap.py | sudo python3 - --admin klein
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 2682 100 2682 0 0 24381 0 --:--:-- --:--:-- --:--:-- 24381
Checking if TLJH is already installed...
Setting up hub environment
Installed python & virtual environment
Set up hub virtual environment
Setting up TLJH installer...
Setup tljh package
Starting TLJH installer...
> /usr/bin/npm pack #jupyterlab/hub-extension
Incompatible extension:
"#jupyterlab/hub-extension#0.12.0" is not compatible with the current JupyterLab
Conflicting Dependencies:
JupyterLab Extension Package
>=0.18.3 <0.19.0 >=0.19.1 <0.20.0 #jupyterlab/application
>=0.18.3 <0.19.0 >=0.19.1 <0.20.0 #jupyterlab/apputils
Found compatible version: 0.11.0
> /usr/bin/npm pack #jupyterlab/hub-extension#0.11.0
> node /opt/tljh/user/lib/python3.6/site-packages/jupyterlab/staging/yarn.js install
> node /opt/tljh/user/lib/python3.6/site-packages/jupyterlab/staging/yarn.js run build
System has not been booted with systemd as init system (PID 1). Can't operate.
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/tljh/hub/lib/python3.6/site-packages/tljh/installer.py", line 447, in <module>
main()
File "/opt/tljh/hub/lib/python3.6/site-packages/tljh/installer.py", line 436, in main
ensure_jupyterhub_service(HUB_ENV_PREFIX)
File "/opt/tljh/hub/lib/python3.6/site-packages/tljh/installer.py", line 141, in ensure_jupyterhub_service
systemd.reload_daemon()
File "/opt/tljh/hub/lib/python3.6/site-packages/tljh/systemd.py", line 19, in reload_daemon
], check=True)
File "/usr/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['systemctl', 'daemon-reload']' returned non-zero exit status 1.
Downloading traefik 1.6.5...
ERROR: Job failed: exit code 1
image: ubuntu:latest
before_script:
- apt-get update
- apt-get install -y curl git ssh python3 rsync sudo
- git submodule update --init --recursive
stages:
- test
- deploy
test_job:
stage: test
script:
- curl
https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/bootstrap/bootstrap.py | sudo python3 - --admin admin
deploy:
stage: deploy
script:
- curl
https://raw.githubusercontent.com/jupyterhub/the-littlest jupyterhub/master/bootstrap/bootstrap.py | sudo python3 - --admin adminn
- mkdir .public
- cp -r * .public
- mv .public public
- mkdir "${HOME}/.ssh"
- echo "${SSH_HOST_KEY}" > "${HOME}/.ssh/known_hosts"
- echo "${SSH_PRIVATE_KEY}" > "${HOME}/.ssh/id_rsa"
- chmod 700 "${HOME}/.ssh/id_rsa"
- rsync -hrvz --delete --exclude=_ public/ user#example.com:www/jupyter/
artifacts:
paths:
- public
only:
- master

AWS ElasticBeanstalk amazon linux pg_config error with psycopg2

I am testing AWS for launching web service.
I stuck with pg_config. Error log is
/app/requirements.txt (line 1))
Using cached psycopg2-2.6.2.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
There are many solutions in stackoverflow, but it doesn't work for me.
packages:
yum:
python-devel: []
postgresql95-devel: []
libjpeg-devel: '6b'
container_commands:
01_migrate:
command: "python manage.py migrate"
02_collectstatic:
command: "python manage.py collectstatic --noinput"
03_createsu:
command: "python manage.py createsu"
leader_only: true
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "onreview.settings"
PYTHONPATH: "$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "onreview/wsgi.py"
This is my .ebextensions/python.config files contents. And I'm uploading through zipping my source code.
I changed postgresql95-devel to postgresql-devel, 93, 94, all of it. And I use 9.5 version db right now.
I think --pg-config's path is problem. but I can't change it.
Is there any solution??
p.s I do not want to setup inside the EC2 instance through SSH or something.
You have a syntax error in your original post, packages: should not be indented. I don't know why you have python-devel when python is included in the install, so I can't say that it isn't interfering. Likewise with the line setting the python path.
packages:
yum:
python-devel: []
postgresql95-devel: []
libjpeg-devel: '6b'
container_commands:
01_migrate:
command: "python manage.py migrate"
02_collectstatic:
command: "python manage.py collectstatic --noinput"
03_createsu:
command: "python manage.py createsu"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "onreview.settings"
PYTHONPATH: "$PYTHONPATH"
aws:elasticbeanstalk:container:python:
WSGIPath: "onreview/wsgi.py"

ckan harvester: "No module named pika" error

On a ckan instance running ok, I installed the harvester extension following this guide: https://github.com/ckan/ckanext-harvest
these are the steps I followed:
. /usr/lib/ckan/default/bin/activate
cd /usr/lib/ckan/default/src/ckan
sudo pip install -e git+https://github.com/okfn/ckanext-harvest.git#stable#egg=ckanext-harvest
cd /usr/lib/ckan/default/src/ckan/src/ckanext-harvest
sudo pip install -r pip-requirements.txt
This is the content of pip-requirements.txt:
pika==0.9.8
redis==2.10.1
I continue configuring the plugin, everything seems to work ok. I have it running at http://localhost/harvest. Then I create a new source, and when I want to start the gather command I get this error:
$ . /usr/lib/ckan/default/bin/activate
$ cd /usr/lib/ckan/default/src/ckan/src/ckanext-harvest
$ paster --plugin=ckanext-harvest harvester gather_consumer --config=/etc/ckan/default/production.ini
Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 9, in <module>
load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 104, in run
invoke(command, command_name, options, args[1:])
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 143, in invoke
exit_code = runner.run(args)
File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/paste/script/command.py", line 238, in run
result = self.command()
File "/usr/lib/ckan/default/src/ckan/src/ckanext-harvest/ckanext/harvest/commands/harvester.py", line 125, in command
from ckanext.harvest.queue import get_gather_consumer, gather_callback
File "/usr/lib/ckan/default/src/ckan/src/ckanext-harvest/ckanext/harvest/queue.py", line 5, in <module>
import pika
ImportError: No module named pika
I'm pretty sure there must be something really silly with the virtualenv (python newbie here)
This is because you used sudo pip. Because of how python's virtualenv works, if you want to use sudo to install into the virtualenv, you need to give full path to pip. Something like this would work
sudo /usr/lib/ckan/default/bin/pip -e git+https://github.com/okfn/ckanext-harvest.git#stable#egg=ckanext-harvest
cd /usr/lib/ckan/default/src/ckanext-harvest
sudo /usr/lib/ckan/default/bin/pip install -r pip-requirements.txt

python and bpython using different PYTHONPATHs in Virtualenv

Something strange and unexpected is happening with the sys.path of any virtual environment I set. For example, a clean env:
$ virtualenv test
$ source test/bin/activate
(test) $
This is the expected PYTHONPATH:
(test) $ python
>>> import sys
>>> print '\n'.join(sys.path)
/home/user/test/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/home/user/test/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/home/user/test/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/home/user/test/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/home/user/test/lib/python2.7
/home/user/test/lib/python2.7/plat-linux2
/home/user/test/lib/python2.7/lib-tk
/home/user/test/lib/python2.7/lib-old
/home/user/test/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/home/user/test/local/lib/python2.7/site-packages
/home/user/test/lib/python2.7/site-packages
But this is the one I really get:
(test) $ bpython
>>> import sys
>>> print '\n'.join(sys.path)
/usr/bin
/usr/lib/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
I can't figure out the reason of the two different sys.paths.
Because of that, no pip installation works!
I'm using Virtualenv 1.7.2, Ubuntu 12.04, Python 2.7.3.
Any help will be appreciated.
Rather than installing one copy of bpython per virtualenv, I've added this function to my shell profile (for example ~/.bashrc or ~/.zshrc). It wraps the bpython command with some logic to load the virtual environment's python path (if you have an active virtual environment).
bpython() {
if test -n "$VIRTUAL_ENV"
then
PYTHONPATH="$(python -c 'import sys; print ":".join(sys.path)')" \
command bpython "$#"
else
command bpython "$#"
fi
}
I found that I needed to deactivate and reactivate my virtualenv after installing bpython for it to work.
pip install bpython
deactivate
. bin/activate # or your equivalent activation command
My hypothesis is that you have not installed bpython after you have activated the new virtualenv.
I followed it up exactly like you mentioned:
mkvirtualenv bpython
(bpython)~ $ pip install bpython
(bpython)~ $bpython
and then ran the commands:
>>> import sys
>>> print '\n'.join(sys.path)
/Users/xxxx/.virtualenvs/bpython/bin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python27.zip
/Users/xxxx/.virtualenvs/bpython/lib/python2.7
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-darwin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-tk
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-old
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-dynload
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages
and did the same thing again by running python under the activated virtualenv
(bpython)~ $ python
.....
>>> import sys
>>> print '\n'.join(sys.path)
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/Users/xxxx/.virtualenvs/bpython/lib/python27.zip
/Users/xxxx/.virtualenvs/bpython/lib/python2.7
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-darwin
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-tk
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-old
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/lib-dynload
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/xxxx/.virtualenvs/bpython/lib/python2.7/site-packages
I saw no difference in the two results
I also discovered that if you have bpython installed locally, you need to create your virtualenv with --no-site-packages for it to work properly. If you created your virtualenv without that flag, you can create an empty file named no-global-site-packages.txt in ~/.virtualenvs/<env-name>/lib/python2.7/ as noted in this Stack Exchange answer.