I have created a wrapper for c++ library using python.
I have a bash script that will download c++ code, compile it and copy the generated .so file to the python package.
Then I have written the setup.py so that when you use pip install package-name, it will install the .so file also.
What I need is to run that bash script when I type pip install package-name. Currently what I have to do is run the bash script first and then use pip install package-name to install.
And I need to upload the code to the Python Package Index. So the solution has to be compatible with that also*.
PS: I know about the Extension module in setuptools. I can't use that because I need to download something and run a Makefile after editing it. I do all of that with the bash script.
* I learnt that this requirement is not possible. So please ignore that one.
Thank you..
Related
Beginner here. I've just learned the basics of python using VS. I don't know why I get a syntax error in the VSCode text file but not on the terminal for the command.
Any assistance helping me understand would be great, thank you.
Tried to install boto3 with pip.
You cannot run shell commands from a python script.
This is the right way to do it. You can also use the subprocess module to do it.
import os
# In Linux
os.system("python3 -m pip install boto3")
# In Windows
os.system("py -m pip install boto3")
Although, it's not recommended installing packages inside your code.
You can use a requirements.txt file. Then you just need to run this command once in your terminal:
pip install -r requirements.txt
py -m pip install boto3
Obviously, this does not conform to python syntax.
Usually we call it a command line.
We run it in the shell instead of python file.
Python files will be compiled and then run. This command line statement will not be compiled (As the wavy line in the file reminds, this is an error code). You can further learn Python syntax to learn more about this problem.
I downloaded a Python package from Github. To use it I had to install an python egg on my computer. I'd like to make some modifications to the package. To do so, I have to recompile the egg each time to test it.
My question is, how do I run the python files directly without having to recompile the egg each time?
You can use an "editable" installation to link to the files directly, without having to build the egg each time.
$ pip install -e ./path/to/package
https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs
I'm trying to make my first UniCurses project with Python on OpenSUSE.
I put the import statement in my .py file, but when I tried to run it, it says the module is not there... So I downloaded UniCurses from the website, and the instructions say Unix's Python already has UniCurses. That's odd, but I continued. I put the downloaded unicurses.py into my project directory, and when I tried running my file, an error message says UniCurses is not compatible with my system, and that either my Python distribution is below v2.6 or my operating system is something other than Windows or a *nix. My Python is v2.7.8, and again, my OS is a Linux distro. Why is this happening, and what should I do?
Edit: It's worth noting that the regular curses supposedly doesn't work on my system either.
Answer by Sagar Rakshe from How to install Python package from GitHub:
To install Python package from github, you need to clone that repository.
git clone https://github.com/jkbr/httpie.git
Then just run the setup.py file from that directory,
sudo python setup.py install
If you have already downloaded the file you can skip the first step and just run the python setup.py install in the folder. (I don't think sudo is necessary for python)
I'm trying to use the gfx module for python (from here: http://www.swftools.org/gfx_tutorial.html). But when I do python setup.py build I get an error:
ImportError: cannot import name CompileError
I just need to open a gfx file.. (Its part of the pythonchallenge.com)
How can I do it?
I'm working on linux mint 64bit
enter code here Not sure how stable this is but there seems to be a lot of issues installing 0.9.2 on ubuntu:
wget http://www.swftools.org/swftools-2013-04-09-1007.tar.gz
tar -xzvf swftools-2013-04-09-1007.tar.gz
cd swftools-2013-04-09-1007/
./configure
make
sudo make install
sudo cp lib/python/*.so /usr/lib/python2.7/site-packages/
That should compile and install on ubuntu.
Then python -c 'import gfx' should work.
I had a look at the setup.py script and it seems it is using CompileError from distutils which is now depreciated, I replaced it with from distutils.core import CCompilerError
Running python setup.py runs after changing but complains about various errors in relation to jpeg and PIL._imaging.so so I have included an instuctions.txt in the file which has instructions on how to setup the required packages and symlinks etc...
I also had to add the lib/art directory from swftools on github and add it to the lib directory.
It runs and installs on ubuntu 14.04 but should work on mint also.
The updated package is here
download
http://www.swftools.org/download.html
You can build the Python module using setup.py
You can build it "manually" by using make
To do the former, all that should be required is
python setup.py build
python setup.py install
This is the preferred way. If the above gives you any trouble or you prefer make, the following will also create the Python module:
./configure
make
# substitute the following path with your correct python
installation:
cp lib/python/*.so /usr/lib/python2.4/site-packages/
You can test whether the python module was properly installed by doing
python -c 'import gfx'
What are the differences between the below commands
python setup.py install develop
Doesn't work for me error No such file or directory: 'build/bdist.macosx-10.7-intel/egg/test-easy-install-37886.pth'
python setup.py develop
Works for me appears to make an .egg link file
python setup.py install
Works for me appears to make a .egg file which in .zip file format
Develop is a setuptools / distribute feature that allows you to add a project
to your Python environment without installing it - so you can continue
its "development"
In other words, when you call "python setup.py develop", setuptools will
compile the metadata and hook your project into Python's site-package,
but the packages and modules that will be used are the one in the
directory where you've run that command.
This is useful to continue working on your code and testing it without
having to run "python setup.py install" on every run
With develop, Python 'pseudo-installs' a package by running the setup.py script instead of install. The difference is a modification of the environment (it doesn't with develop), so a package can be imported from it's current location instead of a site-package directory. The advantage of this is you can develop packages that are being used by other packages, and you can modify source code in place with develop.
As far as "setup.py install develop", I've never seen anyone use that before, sorry.
source
source
source
python setup.py install develop
Is a wrong command.
When you use develop you use the current code when you run your application.
When you useĀ install and then modify you code, your modifications will not be taken in account while running your app. until you rerun install or develop.