I gave my friends a project. and I use lots of 3rd part packages among the scripts.
How could I generate all the necessary packages automatically.
Otherwise,
my friend should run my script and catch the exception and install the missing package, again and again.
By the way, is it possible to install all the necessary packages at once ?
# -*- coding: utf8 -*-
from flask import request, url_for
from flask import json
from flask import Response
from flask import Flask, request, jsonify
from flask_request_params import bind_request_params
import datetime
import pandas as pd
import pymongo
import pdb
from webargs import Arg
from webargs.flaskparser import use_args, use_kwargs
import urlparse
from mongo import Mongo
import yaml
import time, functools
from functools import wraps
from pdb import set_trace
from flask import g
from pandas_helper import PandasHelper
import errors
That’s what requirement files in pip are for:
"Requirements files" are files containing a list of items to be installed using pip install
Basically they document your dependencies, so when you do a pip install later, pip will get all the required dependencies to run your script.
Related
import argparse
import os
from flask import Flask, jsonify, make_response
!pip install flask_cors
!pip install flask_swagger_ui
from flask_cors import CORS
from flask_swagger_ui import get_swaggerui_blueprint
!pip install routes
from routes import request_api
this is the whole code I tried it in colab but the last import keeps failing
I got code from https://github.com/Sean-Bradley/Seans-Python3-Flask-Rest-Boilerplate/blob/master/app.py
You should add the module on your own.
try to open https://github.com/Sean-Bradley/Seans-Python3-Flask-Rest-Boilerplate/tree/master/routes
and copy those modules to your folder.
I have installed all the Node.js libraries as required for my nodejs application. But the nodejs application at the backend uses python libraries which has some lines of code such as import nltk and all other libraries. and these import statements when uploaded on a heroku platform is raising an error.
Traceback (most recent call last): File "mainfile.py", line 2, in import functionfile as f File "/app/functionfile.py", line 1, in import nltk ModuleNotFoundError: No module named 'nltk'
I have uploaded all the files but still it is raising an error.
complete code deployed on heroku is available in github link - https://github.com/rinku16/patranker
nodejs application code files is present in app folder
Issue: How can i use this nltk and other python libraries in my application.
Below are the python libraries required in the python file
# Import function file as reference to use defined python functions
import functionfile as f
import sys
import nltk
from nltk.corpus import stopwords
#for generating sentence token
from nltk.tokenize import sent_tokenize
#for generating word token
from nltk.tokenize import word_tokenize
# BeautifulSoup for scraping and Requests to make HTTP requests.
from bs4 import BeautifulSoup
# BeautifulSoup is in bs4 package
import requests
#Counter class For Getting Most Occurred Biwords
from collections import Counter
#FOR MAKING DATA FRAME AND WRITING THE PATENT EXTRACTED DATA TO CSV FILE
from pandas import DataFrame
import pandas as pd
import os
import os.path
from os import path
import re
from datetime import datetime, timedelta
from datetime import date
import math
For example, for nltk library below is path of the file i got
>>> import nltk
>>> nltk.__file__ 'C:\\Users\\Carthaginian\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\nltk\\__init__.py'
how i use this path to clone it in my nodejs application. please see this.
You can create a custom_lib folder and clone all the libraries in it. Provide the correct path using import or require in Node.js project. Use gulp runner or any task runner to copy these custom_lib to your build folder and remember follow the same hierarchy in the build folder structure.
You can also write a custom script to copy these python_lib to the build folder. You can add this custom script in package.json in scripts.
We have the same issue in our project and it work like a charm.
I'm trying to run this python project on my linux machine. I did setup everything according to the requirement but when I try to run the project with the ./generate.sh executable file I got the following error.
Import Error: No module name tqdm found.
Here are the imports exists in file.
import os.path as path
import ast
from glob import glob
import signal
import imp
import logging
import time
import numpy as np
import socket
import tqdm
import sys
import click
import tensorflow as tf
from tensorflow.python.client import timeline
I check with pip3 show tqdm command it shows me the package detail. I also try to uninstall and install again the project but got no luck.
If i remove the tqdm import from the file then it shows me this error.
File "./run.py", line 16, in <module>
import click
ImportError: No module named click
Can someone guide me what I'm doing wrong here?
it seems you are importing it wrong, from tqdm docs:
from tqdm import tqdm
I've checked it for both python2 and 3 and this is the way to use it.
The project you are trying to use at least 3 years old, so maybe things have changed since then, so if it wont work for you even with proper import statement you can simply remove it.
Every loop working with tqdm will work without it as well.
For example:
from tqdm import tqdm
for i in tqdm(range(10000)):
pass
is the same as:
for i in range(10000)):
pass
I am trying to implement the code in https://github.com/kexinyi/ns-vqa.
However, when I try the command, python tools/preprocess_questions.py \ ... in the section of "Getting started". I see a message No module named 'utils.programs'.
Then I install utils and which makes import utils work, but import utils.programs does not work.
Does anyone have any idea to solve it?
import os
import argparse
import json
import h5py
import numpy as np
import utils.programs as program_utils # this one cannot be imported
import utils.preprocess as preprocess_utils
import utils.utils as utils
Solution:
Add the below lines at the beginning of preprocess_questions.py file.
import sys
sys.path.insert(0, "..")
This should solve your problem.
Explanation:
It is failing because preprocess_questions.py don't know about the path of utils.programs to import. With the above lines added to the path using .., the required file will be imported.
For more on this refer how importing works in python.
PEP8 suggests that:
Imports should be grouped in the following order:
standard library imports
related third party imports
local application/library specific imports
You should put a blank line between each group of imports.
I am using Flake8Lint which Sublime Text plugin for lint Python files.
My code as below:
import logging
import re
import time
import urllib
import urlparse
from flask import Blueprint
from flask import redirect
from flask import request
from flask.ext.login import current_user
from flask.ext.login import login_required
from my_application import one_module
it will show the warning as below:
import statements are in the wrong order, from my_application should be before from from flask.ext.login
but flask is the third party library, it should before my my_application import. This is why? How to fix it?
The flake8-import-order plugin needs to be configured to know which names should be considered local to your application.
For your example, if using a .flake8 ini file in your package root directory, it should contain:
[flake8]
application_import_names = my_application
Alternatively you can use only relative imports for application local imports:
from __future__ import absolute_import
import os
import sys
import requests
from . import (
client
)
...