My startup command I have for my discord.py bot installs requirements from a requirements.txt file and puts them into the specified folder (the requirements folder) but the issue I'm having is that the bot doesn't look into that folder for dependencies and just looks at the root folder instead
Is there a way I could make the bot look at a specific folder for dependencies instead of the root one? Because if I were to use the root folder, it'd make it look messy and harder to navigate
Here is the command I use:
pip install -U --target /home/container/requirements -r requirements.txt; fi; /usr/local/bin/python /home/container/bot.py
If I understand correctly, You need to use a virtual environment.
You can do that with may ways venv poetry pipenv.
I recommend you use pipenv all you have to do is install your requirements.txt to the environment and then run your code inside of it.
pipenv install -r requirements.txt
I'm trying to implement Deploy to Heroku functionality for my Python application:
https://github.com/jet-admin/jet-bridge/tree/heroku
It woks OK if just use requirements.txt to install dependencies, but it require me to modify my requirements.txt to include some extra packages that i normally don't need (psycopg2, mysqlclient).
Is it possible not to include all requirements in requirements.txt, but install it with some extra command? I've tried adding postdeploy script which will perform pip install command, but after deploy succed my application says that psycopg2 is not installed (thought i installed it in postdeploy command).
The Heroku Python buildpack has a hook where you can execute extra commands after the initial slug compilation.
To use it, you can add a bin/post_compile file, putting inside the shell commands for installing the extra packages.
You can even make it depend on an environment variable, like:
# assuming you have files mysql-requirements.txt and postgres-requirements.txt
if [ "$JET_BRIDGE_DB" == "mysql" ]; then
echo "Installing Python dependencies for MySQL support"
pip install -r mysql-requirements.txt
else
echo "Assuming Postgres database, installing Python dependencies"
pip install -r postgres-requirements.txt
fi
Read more:
Buildpacks: https://devcenter.heroku.com/articles/buildpacks
Heroku Python Buildpack: https://github.com/heroku/heroku-buildpack-python
Slug compilation: https://devcenter.heroku.com/articles/slug-compiler
So, I'm writing a simple command-line Python app that maintains some user data. I thought to implement setuptools to make the build and distribution process easier, but I can't find a good solution to manage the user files.
It is easy enough to create a user directory in /etc/appname, but when a user wants to uninstall my application, presumably with:
sudo pip uninstall appname
It won't remove the /etc/appname directory holding the users. It'll only remove the .egg file.
Is there a way to specifiy in setup.py a script that will run when uninstall is called, so I can manually remove the directories I've created?
Or is there an option to have setuptools create a data directory for the purpose of read and writing to files from the application and not just read-only config files?
I didn't find a proper way to manage dynamic files with setuptools, so I used a Makefile. It creates the directories for the program to reference, then runs setuptools to gather pip packages and install the script to /usr/bin.
install:
mkdir -p ~/.appname/users
sudo python setup.py install
cp -u appname/users/* ~/.appname/users
uninstall:
sudo rm -rf ~/.appname
sudo pip uninstall appname
I've got a Python virtual environment that is intended to provide an environment for many people.
It is to be stored in SVN in order to ensure that the environment is "frozen" for various releases.
I have attempted to make it "dynamic" in the sense that the environment activation script is made to not contain a hardcoded path and I have attempted to make it relocatable because it is to be used by many people at many different directories.
I have archived the environment because storing it as a directory in the repository would mean that updates to the environment would result in SVN change summaries that would be almost unreadable.
In have split the archive across multiple files in order to respect SVN file size restrictions.
Is this approach robust? Are there likely to be problems when multiple people use it at multiple directories? Is archiving in the way I am doing it a good idea? Are there better approaches to any of the ideas I've expressed?
The specific procedure I'm using is something like the following:
ssh "${USER}"#sern.ch
setupSALTAEnvironment
echo "create Python virtual environment"
virtual_environment_name="virtual_environment"
virtualenv "${virtual_environment_name}"
echo "make activation dynamic"
activate_filename="virtual_environment/bin/activate"
temporary_filename="/tmp/"$(date "+%Y-%m-%dT%H%MZ" --utc)""
cat > "${temporary_filename}" << "EOF"
directory_bin="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
directory_env="$(dirname "${directory_bin}")"
VIRTUAL_ENV="${directory_env}"
EOF
sed -i "/^VIRTUAL_ENV.*/ {
r ${temporary_filename}
d
}" "${activate_filename}"
rm "${temporary_filename}"
echo "activate Python virtual environment"
source "${virtual_environment_name}"/bin/activate
IFS= read -d '' text << "EOF"
import sys
reload(sys)
sys.setdefaultencoding("utf8")
EOF
echo "${text}" > "${virtual_environment_name}"/lib/python2.7/site-packages/sitecustomize.py
echo "install software in Python virtual environment"
pip install docopt
pip install dataset
pip install numpy
pip install matplotlib
pip install pyfiglet
pip install datavision
pip install nodemaster
pip install propyte
pip install git+https://github.com/wdbm/pyprel.git
pip install git+https://github.com/wdbm/pyrecon.git
pip install shijian
pip install technicolor
#pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
#pip install git+git://github.com/google/skflow.git
echo "make Python virtual environment relocatable"
virtualenv --relocatable virtual_environment
echo "archive Python virtual environment with respect to SVN limitations"
tar -czf - virtual_environment/ | split --bytes=50MB - virtual_environment.tgz.
rm -rf virtual_environment
Am on Debian 5, I've been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the following link here).
Then, I used the scripts in /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin to populate environment variables such as PATH, ORACLE_HOME and NLS_LANG.
Once, this was completed, I tried to run:
sudo easy_install cx_oracle
But I keep getting the following error:
Searching for cx-oracle
Reading http://pypi.python.org/simple/cx_oracle/
Reading http://cx-oracle.sourceforge.net
Reading http://starship.python.net/crew/atuining
Best match: cx-Oracle 5.0.4
Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download
Processing cx_Oracle-5.0.4.tar.gz
Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-xsylvG/cx_Oracle-5.0.4/egg-dist-tmp-8KoqIx
error: cannot locate an Oracle software installation
Any idea what I missed here?
The alternate way, that doesn't require RPMs. You need to be root.
Dependencies
Install the following packages:
apt-get install python-dev build-essential libaio1
Download Instant Client for Linux x86-64
Download the following files from Oracle's download site:
Extract the zip files
Unzip the downloaded zip files to some directory, I'm using:
/opt/ora/
Add environment variables
Create a file in /etc/profile.d/oracle.sh that includes
export ORACLE_HOME=/opt/ora/instantclient_11_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
Create a file in /etc/ld.so.conf.d/oracle.conf that includes
/opt/ora/instantclient_11_2
Execute the following command
sudo ldconfig
Note: you may need to reboot to apply settings
Create a symlink
cd $ORACLE_HOME
ln -s libclntsh.so.11.1 libclntsh.so
Install cx_Oracle python package
You may install using pip
pip install cx_Oracle
Or install manually
Download the cx_Oracle source zip that corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:
python setup.py build
python setup.py install
I recommend that you grab the rpm files and install them with alien. That way, you can later on run apt-get purge no-longer-needed.
In my case, the only env variable I needed is LD_LIBRARY_PATH, so I did:
echo export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib >> ~/.bashrc
source ~/.bashrc
I suppose in your case that path variable will be /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.
The following worked for me, both on mac and Linux. This one command should download needed additional files, without need need to set environment variables.
python -m pip install cx_Oracle --pre
Note, the --pre option is for development and pre-release of the Oracle driver. As of this posting, it was grabbing cx_Oracle-6.0rc1.tar.gz, which was needed. (I'm using python 3.6)
Thx Burhan Khalid, I overlooked your "You need to be root" quote, but found the way when you are not the root here.
At point 7 you need to use:
sudo env ORACLE_HOME=$ORACLE_HOME python setup.py install
Or
sudo env ORACLE_HOME=/path/to/instantclient python setup.py install
Thanks Burhan Khalid. Your advice to make a a soft link make my installation finally work.
To recap:
You need both the basic version and the SDK version of instant client
You need to set both LD_LIBRARY_PATH and ORACLE_HOME
You need to create a soft link (ln -s libclntsh.so.12.1 libclntsh.so in my case)
None of this is documented anywhere, which is quite unbelievable and quite frustrating. I spent over 3 hours yesterday with failed builds because I didn't know to create a soft link.
I think it may be the sudo has no access to get ORACLE_HOME.You can do like this.
sudo visudo
modify the text add
Defaults env_keep += "ORACLE_HOME"
then
sudo python setup.py build install
Alternatively you can install the cx_Oracle module without the PIP using the following steps
Download the source from here https://pypi.python.org/pypi/cx_Oracle
[cx_Oracle-6.1.tar.gz ]
Extract the tar using the following commands (Linux)
gunzip cx_Oracle-6.1.tar.gz
tar -xf cx_Oracle-6.1.tar
cd cx_Oracle-6.1
Build the module
python setup.py build
Install the module
python setup.py install
This just worked for me on Ubuntu 16:
Download ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip') from Oracle web site and then do following script (you can do piece by piece and I did as a ROOT):
apt-get install -y python-dev build-essential libaio1
mkdir -p /opt/ora/
cd /opt/ora/
## Now put 2 ZIP files:
# ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip')
# into /opt/ora/ and unzip them -> both will be unzipped into 1 directory: /opt/ora/instantclient_12_2
rm -rf /etc/profile.d/oracle.sh
echo "export ORACLE_HOME=/opt/ora/instantclient_12_2" >> /etc/profile.d/oracle.sh
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME" >> /etc/profile.d/oracle.sh
chmod 777 /etc/profile.d/oracle.sh
source /etc/profile.d/oracle.sh
env | grep -i ora # This will check current ENVIRONMENT settings for Oracle
rm -rf /etc/ld.so.conf.d/oracle.conf
echo "/opt/ora/instantclient_12_2" >> /etc/ld.so.conf.d/oracle.conf
ldconfig
cd $ORACLE_HOME
ls -lrth libclntsh* # This will show which version of 'libclntsh' you have... --> needed for following line:
ln -s libclntsh.so.12.1 libclntsh.so
pip install cx_Oracle # Maybe not needed but I did it anyway (only pip install cx_Oracle without above steps did not work for me...)
Your python scripts are now ready to use 'cx_Oracle'... Enjoy!
This worked for me
python -m pip install cx_Oracle --upgrade
For details refer to the oracle quick start guide
https://cx-oracle.readthedocs.io/en/latest/installation.html#quick-start-cx-oracle-installation
If you are trying to install in MAC , just unzip the Oracle client which you downloaded and place it into the folder where you written python scripts.
it will start working.
There is too much problem of setting up environmental variables.
It worked for me.
Hope this helps.
Thanks
Try to reinstall it with the following code:
!pip install --proxy http://username:windowspwd#10.200.72.2:8080 --upgrade --force-reinstall cx_Oracle
If you require to install a specific version of cx_Oracle, like 7.3 which was the last version with support for Python 2, you can do the following:
python -m pip install cx_Oracle==7.3