Forums

How to change python version

I want to change to 3.6

You can use any Python version you like; in bash, python will run 2.7, but python3.6 will run 3.6, and so on for other versions. If you're trying to run 3.6 code somewhere else inside PythonAnywhere, let us know where it is and we can tell you exactly what you need to do.

I have uploaded a script onto pythonanywhere and whenever i press Run in the upper right hand corner of the script, it always runs in Python 3.7. How do I make it run in 3.6?

take a look at https://help.pythonanywhere.com/pages/SaveAndRunPythonVersion/

This advise doesn't seem to work. I'm trying to use the hashbang to switch to python 3.6: #!/usr/bin/python3.6

However, environment is still 3.8 when using save/run button, causing numpy issues:

File "/usr/lib/python3.8/site-packages/numpy/core/overrides.py", line 16, in <module> add_docstring( RuntimeError: implement_array_function method already has a docstring

I have 3.6 configured from my .bashrc but I don't think it's being sourced in that console. Am I missing something?

hmm- I would kill that python console and try to do a new save and run. do you mind pointing us to the file that this is happening in? (and for us to look at it?)

please how can i change the default Python 2.7 in bash to 3.8?

Unfortunately the operating system requires that the command python should always run Python 2.7. But you can always run other versions by using the appropriate command, for example python3.8 for 3.8.

I am having this problem too! and it has gotten very overwhelming. the system does not even build the wxPython , numpy . I defined python 3.6 as my work environment and it keeps giving me the console on python3.8. Any solution not involving me to continue spending days trying to get this solved will be appreciated. NONE of the solutions in the wiki, forums, help or anywhere else online has solved it. I have lost days in this issue. Please forward an intuitive step by step solution. The libraries run well in the stand alone python application so seems the problem may be pythonanywhere. I hope the team to have compassive human delicacy to respond.

What do you mean by "keeps giving me the console on python3.8"? What are your exact steps?

Hi,

I have a similar issue where I cloned my GitHub repo and create a virtual environment with : mkvirtualenv --python=/usr/bin/python3.8.5 crs_venv

Then when I want to install my packages, I run: pip install -r requirements.txt

I get a depreciation warning and an error: ERROR: ipykernel-5.3.4-py3-none-any.whl is not a supported wheel on this platform.

if I instead install using pip3, I get an error saying ERROR: Could not find a version that satisfies the requirement anaconda-client==1.7.2 (from -r requirements.txt (line 2)) (from versions: 1.1.1, 1.2.2) ERROR: No matching distribution found for anaconda-client==1.7.2 (from -r requirements.txt (line 2))

Any help would be appreciated.

What do you see if you run which pip when inside your virtualenv? It would also be interesting to know what you get if you run pip --version.

Having the following error.

~/my_site/personal_web/mysite/my_app (main)$ python trial.py
Traceback (most recent call last):
  File "trial.py", line 37, in <module>
    with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
TypeError: __init__() got an unexpected keyword argument 'context'

This did not happen 2 months ago. I had made sure all of my codes were running, but now none of them do.

[edit by admin: formatting]

Perhaps you were using a virtualenv earlier? When you're not using a virtualenv, the command python will run Python 2.7 (which is unfortunately a requirement of the operating system).

I can see that your website is configured to use a virtualenv called myproj, so if you wan the code that you're running from a Bash console to use that env, then you should first run the command

workon myproj

-- once that is done, you'll see (myproj) appear in the prompt in Bash, and the command python will be bound to the version of Python that your website uses, with all of the modules that you've installed into the virtualenv available.

please I am having errors ModulenotFound error in the wsgi. could this be because of different python versions?

Make sure your web app is set up to use the same Python version / virtual environment you installed your modules for/to (or vice versa).

I have this error ImportError: /lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' how to solve this error?

What are you trying to import when you get that error? Have you changed your system image? If you have, you mat need to re-create your virtualenv.

.

Traceback (most recent call last):
  File "/home/fingerprint/mysite/finegerprint_pipline.py", line 79, in <module>
    results = fingerprint_pipline(img)
  File "/home/fingerprint/mysite/finegerprint_pipline.py", line 44, in fingerprint_pipline
    gabor_img = gabor_filter(normim, angles, freq)
  File "/home/fingerprint/mysite/./utils/gabor_filter.py", line 43, in gabor_filter
    array = np.linspace(-block_size,block_size,(2*block_size + 1))
  File "<__array_function__ internals>", line 5, in linspace
  File "/usr/local/lib/python3.10/site-packages/numpy/core/function_base.py", line 120, in linspace
    num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer
>>>

Getting above error. i have tried it in my local with 3.7 and it was working fine. i have tried to create the VD for python 3.7 but it atkes as 3.10 by default. can you please help me on this

[edit by admin: formatting]

Could you give some more details? How are you running the code -- from a console, or perhaps using the "Save and run" button in the editor? Or some other way?

Yes, using save and run button in the editor.i have created the webapp using python 3.7 but when run the python file getting the error which seems like 'usr/local/lib/python3.10/site-packages/numpy/core/function_base.py'.

Please suggest i m kind of stuck here

There's a setting for the Python version to be used by the "save & run" button in the editor -- it's on the Account page, tab "System image", section "Default Python Versions".

Hi,Thank you so much! It's working fine. but now i have my Flask API. when i am trying to run my app i am getting below errors.

https://www.pythonanywhere.com/user/fingerprint/files/var/log/fingerprint.pythonanywhere.com.error.log

2023-04-06 11:43:56,792: Error running WSGI application
2023-04-06 11:43:56,796: ModuleNotFoundError: No module named 'utils'
2023-04-06 11:43:56,796:   File "/var/www/fingerprint_pythonanywhere_com_wsgi.py", line 16, in <module>
2023-04-06 11:43:56,796:     from finegerprint_pipline import app as application  # noqa
2023-04-06 11:43:56,796: 
2023-04-06 11:43:56,796:   File "/home/fingerprint/mysite/finegerprint_pipline.py", line 5, in <module>
2023-04-06 11:43:56,796:     from utils.poincare import calculate_singularities
2023-04-06 11:43:56,796: ***************************************************

I have this folder utils in mysite and i am using that in my different modules finegerprint_pipline.py file like below:

from utils.poincare import calculate_singularities
from utils.segmentation import create_segmented_and_variance_images
from utils.normalization import normalize
from utils.gabor_filter import gabor_filter
from utils.frequency import ridge_freq
from utils import orientation
from utils.crossing_number import calculate_minutiaes
from tqdm import tqdm
from utils.skeletonize import skeletonize

Please help me

[edit by admin: formatting]

What code do you have to set up the path in your WSGI file? And what directory is the utils directory in?

Its normal flask api.i dint write anything for wsgi file and util is one of my folder in the application contains couple of python file which I have tried to call from my main python file as import module

OK, but perhaps you could share what the code actually is? It's hard to advise on what is going wrong without knowing.

Hi okay.below is my code

import cv2 as cv
from glob import glob
import os
import numpy as np
import sys
from utils.poincare import calculate_singularities
from utils.segmentation import create_segmented_and_variance_images
from utils.normalization import normalize
from utils.gabor_filter import gabor_filter
from utils.frequency import ridge_freq
from utils import orientation
from utils.crossing_number import calculate_minutiaes
from tqdm import tqdm
from utils.skeletonize import skeletonize
from flask import Flask
application = Flask(__name__)

sys.path.insert(0, '/home/fingerprint/mysite/utils')

@application.route('/')
def hello_world():

    return """

            <html>

            <head>

                <title>Python Anywhere hosted web application</title>

            </head>

            <body>

            <h1>Hello, World!</h1>

            <p>

                This is the default welcome page for a

                <a href="https://www.pythonanywhere.com/">PythonAnywhere</a>

                hosted web application.

            </p>

            <p>

                Find out more about how to configure your own web application

                by visiting the <a href="https://www.pythonanywhere.com/web_app_setup/">web app setup</a> page

            </p>

            </body>

            </html>"""


def fingerprint_pipline(input_img):
    block_size = 16

    # pipe line picture re https://www.cse.iitk.ac.in/users/biometrics/pages/111.JPG
    # normalization -> orientation -> frequency -> mask -> filtering

    # normalization - removes the effects of sensor noise and finger pressure differences.
    normalized_img = normalize(input_img.copy(), float(100), float(100))

    # color threshold
    # threshold_img = normalized_img
    # _, threshold_im = cv.threshold(normalized_img,127,255,cv.THRESH_OTSU)
    # cv.imshow('color_threshold', normalized_img); cv.waitKeyEx()

    # ROI and normalisation
    (segmented_img, normim, mask) = create_segmented_and_variance_images(normalized_img, block_size, 0.2)

    # orientations
    angles = orientation.calculate_angles(normalized_img, W=block_size, smoth=False)
    orientation_img = orientation.visualize_angles(segmented_img, mask, angles, W=block_size)

    # find the overall frequency of ridges in Wavelet Domain
    freq = ridge_freq(normim, mask, angles, block_size, kernel_size=5, minWaveLength=5, maxWaveLength=15)

    # create gabor filter and do the actual filtering
    gabor_img = gabor_filter(normim, angles, freq)

    # thinning oor skeletonize
    thin_image = skeletonize(gabor_img)

    # minutias
    minutias = calculate_minutiaes(thin_image)

    # singularities
    singularities_img = calculate_singularities(thin_image, angles, 1, block_size, mask)

    # visualize pipeline stage by stage
    output_imgs = [input_img, normalized_img, segmented_img, orientation_img, gabor_img, thin_image, minutias, singularities_img]
    for i in range(len(output_imgs)):
        if len(output_imgs[i].shape) == 2:
            output_imgs[i] = cv.cvtColor(output_imgs[i], cv.COLOR_GRAY2RGB)
    results = np.concatenate([np.concatenate(output_imgs[:4], 1), np.concatenate(output_imgs[4:], 1)]).astype(np.uint8)

    return results


if __name__ == '__main__':
    # open images
    img_dir = './sample_inputs/*'
    output_dir = './output/'
    def open_images(directory):
        images_paths = glob(directory)
        print(images_paths)
        return np.array([cv.imread(img_path,0) for img_path in images_paths])

    images = open_images(img_dir)

    # image pipeline
    os.makedirs(output_dir, exist_ok=True)
    for i, img in enumerate(tqdm(images)):
        results = fingerprint_pipline(img)
        cv.imwrite(output_dir+str(i)+'.png', results)
        # cv.imshow('image pipeline', results); cv.waitKeyEx()

Thanks for those details. However, it's specifically the contents of the WSGI file that we would need to see in order to help. The WSGI file is accessible from the "Web" page inside PythonAnywhere.

How to run script on python 3.8. Pls i need help

  • If you're running it from bash, use the python3.8 command instead of just python
  • If you're running it fun the editor, see this help page
  • If you want to use it for a website you've set up on the "Web" page, just change the version on that page.

If you're trying to run it some other way, could you give some more details?

how can i change my python verison to 3.11

We don't support Python 3.11 right now -- it's coming soon, though!