I am given a project in a college. The task is to create automated test suite for a web application feature. The automation project will generate report fo the tests. I will use selenium for the project. The task requires that "no dependencies" should be added manually when running the project on another machine. All dependencies should be inside the project or installed by project itself. I didn't understand how it can be possible. Well, I can make a requirements.txt file and the user can use a single pip command to install all dependencies, however, it is also considered "adding manually". How the project itself can install all dependencies?
You can add all the requirements using the "pip freeze" in the requirements.txt file and then you can add this line of code in your main file like.
import os
os.system('pip install -r requirements.txt')
Related
I need to copy my project from machine A to machine B.
If I copy the project to another machine I need to install all external libraries/frameworks for python before that.
Is it possible to include all imported external libraries and frameworks into the project structure?
For instance, I'm using Flask inside of the project. I would like to configure my project in a way when I do not need to install Flask in machine B to run the project.
If I would like to solve the same task in java I just need to create a war/jar file. After that, just copy a jar file to the machine B.
Machine B does not have access to the internet so I can't use pip freeze / pyinstaller.
Normally you create a requirements.txt file and list out all the dependencies of your project in it, so that a single installation command can be used to install those dependencies on a different system (or re install on the same system). This is the answer given by #Vignesh Rajendran.
However for this method to work, the new system must have an internet connection. But since you stated that's not the case, you can use the below method instead.
Have a virtual environment. When you need to move the project to a new system, you can move the environment folder along with the source code. You can find a good tutorial for the same here.
My suggestion is to create a requirement file / Executable file
For Requirement file:(Option 1)
you can create a requirements.txt file by using the below command from Machine A.
pip freeze > requirements.txt
the file looks like this
numpy==1.18.4
openpyxl==3.0.3
pandas==1.0.3
and then copy your code along with the requirements.txt file to machine B and enter this command
pip install -r requirements.txt
All the Packages in the Machine A will be installed to B using a single command
For Executable file:(Option 2)
installer Pyinstaller in Machine A and create Executable using below command
pip install pyinstaller
pyinstaller --onefile yourscript.py
exe will be generated and available in the dist Folder copy this to Machine B
But this needs some changes in code for folder paths and hardcoded stuffs as exe cann't be edited on Maachine B
I'm trying to develop a django application to share with a project team. At this point, I have the alpha release of the application ready to share. Following the instructions on how to package a django app, I copied it to a separate folder, made all the files, and ran setup.py. It made my .zip file and all was good.
My confusion is, now that I did that, as per step (1) in the tutorial, my code is sitting outside my django project folder. How am I supposed to develop code if I can't easily run manage.py for migrate and runserver? Am I really expected to run setup.py, create a new package, and run pip upgrade every time I make a change?
In short, is there a way I can run setuptools while keeping the source code in the django folder?
Use the -e flag to pip install to install the project in editable/develop mode.
pip install -e path/to/my/source
I recently wrote my first setup.py (with distutils) for an application I'm working on. This installed the library in /usr/local/lib/python and the executable script in /usr/local/bin. This is great, except I want to continue working on it, and whenever I call my application it first looks in /usr/local and runs it from there, instead of the directory I'm at. So I have to manually go and delete the files form these locations. What is the proper way to do this?
If you've got it all packaged up you should be able to say
python setup.py develop
and it will install it locally for you to test.
Then, if you want to uninstall it just
pip uninstall my_package
I am starting on a project for classified ad listing site and found a template to get me started.
The installation instruction on git are not clear to me.
I created virtual env and installed dependencies using pip but I can't finish the installation process: manage.py runserver could not be executed and showed "could not find module sorl.thumbnail".
I think there is some error due to folder structure but cannot figure out what. Any ideas?
This is my folder structure.
It seems that the dependency sorl.thumbnail is not (successfully) installed.
Try running pip install sorl-thumbnail==11.05.2. That should install the module (in the version required by django-classifieds according to the requirements.txt). Check the output for any errors.
Also, make sure that you are using the right environment.
My only guess is that you either forgot to install sorl.thumbnail or that it is in a separate environment than django-classifieds. To add it manually, download the zip from the specified URL, extract the zip, and, in a command prompt/terminal in the directory you extracted the zip into, and run python setup.py build and python setup.py install.
I'd like to start developing an existing Python module. It has a source folder and the setup.py script to build and install it. The build script just copies the source files since they're all python scripts.
Currently, I have put the source folder under version control and whenever I make a change I re-build and re-install. This seems a little slow, and it doesn't settle well with me to "commit" my changes to my python install each time I make a modification. How can I cause my import statement to redirect to my development directory?
Use a virtualenv and use python setup.py develop to link your module to the virtual Python environment. This will make your project's Python packages/modules show up on the sys.path without having to run install.
Example:
% virtualenv ~/virtenv
% . ~/virtenv/bin/activate
(virtenv)% cd ~/myproject
(virtenv)% python setup.py develop
Virtualenv was already mentioned.
And as your files are already under version control you could go one step further and use Pip to install your repo (or a specific branch or tag) into your working environment.
See the docs for Pip's editable option:
-e VCS+REPOS_URL[#REV]#egg=PACKAGE, --editable=VCS+REPOS_URL[#REV]#egg=PACKAGE
Install a package directly from a checkout. Source
will be checked out into src/PACKAGE (lower-case) and
installed in-place (using setup.py develop).
Now you can work on the files that pip automatically checked out for you and when you feel like it, you commit your stuff and push it back to the originating repository.
To get a good, general overview concerning Pip and Virtualenv see this post: http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django
Install the distrubute package then use the developer mode. Just use python setup.py develop --user and that will place path pointers in your user dir location to your workspace.
Change the PYTHONPATH to your source directory. A good idea is to work with an IDE like ECLIPSE that overrides the default PYTHONPATH.