ModuleNotFoundError: No module named 'anvil.server'; 'anvil' is not a package

Trying to run the example from my_uplink_script.py, but getting the error:

import anvil.server

ModuleNotFoundError: No module named 'anvil.server'; 'anvil' is not a package

Below is my installation log

$ pip3 install anvil

Collecting anvil

Using cached anvil-0.0.2-py2.py3-none-any.whl (9.1 kB)

Requirement already satisfied: jinja2>=2.7.3 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil) (2.11.2)

Requirement already satisfied: pyyaml>=3.11 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil) (5.3.1)

Requirement already satisfied: MarkupSafe>=0.23 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from jinja2>=2.7.3->anvil) (1.1.1)

Installing collected packages: anvil

Successfully installed anvil-0.0.2

$ pip3 install anvil-uplink

Requirement already satisfied: anvil-uplink in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.3.30)

Requirement already satisfied: ws4py in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil-uplink) (0.5.1)

Requirement already satisfied: six in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil-uplink) (1.14.0)

Requirement already satisfied: argparse in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil-uplink) (1.4.0)

Requirement already satisfied: future in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from anvil-uplink) (0.18.2)


**Python 3.8.2 (default, Mar 20 2020, 17:21:55)** 

[Clang 11.0.0 (clang-1100.0.33.17)] on darwin

Type "help", "copyright", "credits" or "license" for more information.
>>> import anvil.server

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/xxx.py", line 3, in <module>
$ import anvil.server

ModuleNotFoundError: No module named 'anvil.server'; 'anvil' is not a package

Hi @juliab.

The package anvil is not produced by Anvil, which is a bit confusing. But, someone got there first: https://pypi.org/project/anvil

I would try to pip uninstall it first. And try running your script again but only with import anvil.server statement. It is possible that the anvil package is masking the anvil module from anvil-uplink.

Good luck. A.

yes like @andersgs says youā€™ve installed the wrong package so would probably need to uninstall first.

pip uninstall anvil
pip install anvil-uplink

linked docs: https://anvil.works/docs/uplink

Iā€™m in the same boat as you. Did you get yours working @juliab?
I installed " pip install anvil-uplink" as you said but still I keep getting that message. Any help would be appreciated @stucork

I made it working by downgrading to Python 3.7 from 3.8. Also, make sure you either did not install package called anvil or un-istall it as it is a completely different app.

Ok. I installed the anvil-uplink thing as I said before and shown in the tutorial: The Uplink: Using Code Outside Anvil

How did you downgrade to Python 3.7?

It seems to have worked in IDLE3 for me. Guess it was playing up Thonny

Iā€™m getting the same error. I tried different versions of Python (3.6, 3.7 & 3.8) without success. Itā€™d be great if anyone can suggest something to try here. :grinning:

If you want to see exactly what I did, I recorded two short videos.

Video 1 (0:40 min) - Installing Anvil-Uplink & Importing anvil.server (Python 3.6)
https://www.loom.com/share/5d09e0a690d446239fd29863e18d7438

Video 2 (1:55 min) - Trying (Python 3.7 & 3.8)
https://www.loom.com/share/7b46e8ba63dc44819b35f89f1b6ae7ad

Details about my computer:
Operating System: Windows 10
Windows Subsystem: Linux (Ubuntu)

I presume the solution above idea doesnā€™t work (there might be a name conflict going on)

$ pip uninstall anvil

have you tried

>>> import anvil
>>> dir(anvil)

or working in a virtual env?

$ virtualenv -p python env
$ source env/bin/activate
$ pip install anvil-uplink
$ python
>>> import anvil.server

First Option - Didnā€™t Work

Second Option - Didnā€™t Work

Any other idea?

Hi @luis.satch, did you try this tutorial?

Hi @Tony.Nguyen, I followed @bridgetā€™s https://anvil.works/learn/tutorials/dashboard

The essence is the same. I was able to install anvil-uplink, but Iā€™m unable to import anvil.server in Python. I get the error: ā€œNo module named ā€˜anvil.serverā€™; ā€˜anvilā€™ is not a packageā€ as per the title of this forum thread.

Hi @i.rajeshwari, I get your point, but since there is no available solution, how about give the above-mentioned tutorial a try?

can you do a pip freeze to see what you have installed?

for virtualenv youā€™d also need to install that first

pip install virtualenv

Sure thing @stucork

can you search for a file called anvil.py and see if you have one that just happens to print something and has variables x, y and dataā€¦ itā€™s likely to be in the same directory that youā€™re working inā€¦


edit:
we worked it out

>>> import anvil
>>> anvil.__file__
/users/..../anvil.py

delete/rename the conflicting file(s) and it worked

3 Likes

Thank you for your help @stucork!

Probably worth to mention that once anvil.py and anvil.pyc were deleted, installing anvil.uplink using pip3 was also very useful as my default was Python2.

2 Likes

Hi,
I had the same issue as luis.satch (with Mac OS), and following this forum it seems I was able to get the virtual environment to work in Terminal. But I want to be working in jupyter notebook, how do I do this in the notebook?

Thanks!

You should be able to launch jupyter inside your vitual environment.
If you do a google search for ā€œrunning jupyter inside a virtual envā€ or similar - you should get some hits.

Donā€™t mean to necro this, but I was dumb and set the name of the file I was using to anvil.py so when I went to import something it was trying to import the file I was currently working in and got this same error.

So if you come here in the future and canā€™t get it to work after the above suggestions make sure you didnt name the file anvil.py.

4 Likes